在我的页面上,我有一个垂直的侧栏,点击一下按钮就会打开.侧边栏从屏幕顶部一直延伸到底部.基本上,当我点击按钮打开侧边栏时,它会覆盖公司徽标和公司名称.我希望侧栏稍微小一点,这样它就不会覆盖公司的标志和名称.以下是侧边栏的代码:

     <body>
    <nav class="navbar navbar-dark bg-dark">
        <div class="container-fluid d-flex justify-content-between p-0">
            <a class="navbar-brand d-flex align-items-center" asp-controller="Home" asp-action="Index">Your .NET Core Application</a>

         
            <button class="openbtn" onclick="openNav()">☰ Open Sidebar</button>
        </div>
    </nav>

    <div id="mySidebar" class="sidebar">
         <a href="javascript:void(0)" class="closebtn" onclick="closeNav()">×</a>
        <a onclick='closeNav()' href="#">About</a>
         <a href="#">Services</a>
        <a href="#">Clients</a>
         <a href="#">Contact</a>
   </div>
   </body>

下面是我用来打开和关闭侧边栏的Java脚本:

<script>
        function openNav() {
            document.getElementById("mySidebar").style.width = "250px";
            document.getElementById("main").style.marginLeft = "250px";
        }

        function closeNav() {
            document.getElementById("mySidebar").style.width = "0";
            document.getElementById("main").style.marginLeft = "0";
        }

  
    </script>

以下是样式表:

<style>
.sidebar {
  height: 100%;
  width: 0;
  position: fixed;
  z-index: 1;
  top: 0;
  left: 0;
  background-color: lightblue;
  overflow-x: hidden;
  transition: 0.5s;
  padding-top: 60px;
}

.sidebar a {
  padding: 8px 8px 8px 32px;
  text-decoration: none;
  font-size: 25px;
  color: #818181;
  display: block;
  transition: 0.3s;
}

.sidebar a:hover {
  color: #f1f1f1;
}

.sidebar .closebtn {
  position: absolute;
  top: 0;
  right: 25px;
  font-size: 36px;
  margin-left: 50px;
}

.openbtn {
  font-size: 20px;
  cursor: pointer;
  background-color: #111;
  color: white;
  padding: 10px 15px;
  border: none;
}

.openbtn:hover {
  background-color: #444;
}

#main {
  transition: margin-left .5s;
  padding: 16px;
}

/* On smaller screens, where height is less than 450px, change the style of the sidenav (less padding and a smaller font size) */
@@media screen and (max-height: 450px) {
  .sidebar {padding-top: 15px;}
  .sidebar a {font-size: 18px;}
}
</style>

这是我的顶级公司名称和徽标栏的外观:

enter image description here

以下是当我单击打开侧栏按钮时的外观:

enter image description here

正如您所看到的,侧栏覆盖了显示"您的.Net Core A"的区域.我希望侧栏从顶部菜单下方开始,这样整个黑色菜单就不会被侧栏覆盖.我怎样才能做到这一点.我试图通过删除侧栏样式表中的填充来移动下面的侧栏:

 .sidebar {
      height: 100%;
      width: 0;
      position: fixed;
      z-index: 1;
      top: 0;
      left: 0;
      background-color: lightblue;
      overflow-x: hidden;
      transition: 0.5s;
      padding-top: 60px;
    }

我试着从上面的样式表中删除"pending-top:60px;",但没有任何影响.

推荐答案

为什么不干脆:

.sidebar {
  top: 40px /* height of navbar */;
  height: calc(100% - 40px /* height of navbar */)
}

Javascript相关问答推荐

React native在不首次加载时渲染的挂钩比上一次渲染期间渲染的挂钩更多

在HTML中使用脚本变量作为背景图像源

如何在加载的元数据上使用juserc和await中获得同步负载?

Flisk和JS错误:未捕获的Syntax错误:意外的令牌'<'

如何使用Echart 5.5.0创建箱形图

获取Uint8ClampedArray中像素数组的宽度/高度

如何解决useState错误—setSelect Image不是函数''

在WordPress中使用带有WPCode的Java代码片段时出现意外令牌错误

rxjs插入延迟数据

闭包是将值复制到内存的另一个位置吗?

有条件重定向到移动子域

基于props 类型的不同props ,根据来自接口的值扩展类型

查询参数中的JAVASCRIPT/REACT中的括号

Nextjs 13.4 Next-Auth 4.2登录(&Quot;凭据&,{});不工作

在FAQ Accodion应用程序中使用React useState时出现问题

使用Reaction窗体挂钩注册日历组件

用于测试其方法和构造函数的导出/导入类

我不知道如何纠正这一点.

与在编剧中具有动态价值的定位器交互

无法使用npm install安装react-dom、react和next