猿问

修复了窗口调整大小时带有侧边栏位置的导航栏

我目前正在开发一个带有导航栏和侧边栏的网页。我的导航栏包含我的页面的类别,即汽车和摩托车。单击后,侧边栏将显示其中包含所选类别的库和参考。但是,每当窗口调整大小时,我的页面都会丢失其格式。侧边栏是固定的,但它可以滚动,看起来它与导航栏断开连接。如何使他们的位置固定?


.navbar-inverse {

  background: black;

  font-size: 18px;

}


.navbar-inverse .navbar-nav>li>a:hover,

.navbar-inverse .navbar-nav>li>a:focus {

  color: #ffb143;

}


.navbar-inverse .navbar-brand:hover,

.navbar-inverse .navbar-brand:focus {

  color: white;

  font-size: 18px;

}


.navbar-brand {

  font-family: 'Lato', sans-serif;

  color: grey;

  font-size: 20px !important;

  margin: 0px;

}


td {

  font-weight: normal;

  padding-left: 55px;

  padding-right: 10px;

  padding-bottom: 18px;

  text-align: center;

}


th {

  font-weight: bold;

  padding-left: 65px;

  padding-right: 50px;

  overflow: hidden;

  white-space: nowrap;

  text-align: center;

}


table#bod {

  width: 100%;

  margin-left: 15px;

  margin-right: 45%;

}


#add {

  margin-left: 10px;

  width: 50px;

}


.sidebar {

  height: 100%;

  width: 200px;

  position: fixed;

  z-index: 1;

  top: 0;

  left: 0;

  background-color: black;

  overflow-x: hidden;

  padding-top: 80px;

  margin-top: 45px;

}



/* Style sidebar links */


.sidebar a {

  padding: 6px 8px 6px 16px;

  text-decoration: none;

  font-size: 18px;

  color: white;

  display: block;

}



/* Style links on mouse-over */


.sidebar a:hover {

  color: #f1f1f1;

}



/* Style the main content */


.main {

  margin-left: 160px;

  /* Same as the width of the sidenav */

  padding: 0px 10px;

}



/* Add media queries for small screens (when the height of the screen is less than 450px, add a smaller padding and font-size) */


@media screen and (max-height: 450px) {

  .sidebar {

    padding-top: 15px;

  }

  .sidebar a {

    font-size: 18px;

  }

}



慕慕森
浏览 133回答 2
2回答

红颜莎娜

如果我理解你的问题......那么我只是减少了侧边栏的 Z-index 并将所有元素的框大小设置为边框框,并将正文的边距和填充设置为 0/* added this */*{padding : 0;margin : 0;box-sizing : border-box;}.navbar-inverse {&nbsp; background: black;&nbsp; font-size: 18px;}.navbar-inverse .navbar-nav>li>a:hover,.navbar-inverse .navbar-nav>li>a:focus {&nbsp; color: #ffb143;}.navbar-inverse .navbar-brand:hover,.navbar-inverse .navbar-brand:focus {&nbsp; color: white;&nbsp; font-size: 18px;}.navbar-brand {&nbsp; font-family: 'Lato', sans-serif;&nbsp; color: grey;&nbsp; font-size: 20px !important;&nbsp; margin: 0px;}td {&nbsp; font-weight: normal;&nbsp; padding-left: 55px;&nbsp; padding-right: 10px;&nbsp; padding-bottom: 18px;&nbsp; text-align: center;}th {&nbsp; font-weight: bold;&nbsp; padding-left: 65px;&nbsp; padding-right: 50px;&nbsp; overflow: hidden;&nbsp; white-space: nowrap;&nbsp; text-align: center;}table#bod {&nbsp; width: 100%;&nbsp; margin-left: 15px;&nbsp; margin-right: 45%;}#add {&nbsp; margin-left: 10px;&nbsp; width: 50px;}.sidebar {&nbsp; height: 100%;&nbsp; width: 200px;&nbsp; position: fixed;&nbsp; z-index: -1;&nbsp; top: 0;&nbsp; left: 0;&nbsp; background-color: black;&nbsp; overflow-x: hidden;&nbsp; padding-top: 80px;&nbsp; margin-top: 45px;}/* Style sidebar links */.sidebar a {&nbsp; padding: 6px 8px 6px 16px;&nbsp; text-decoration: none;&nbsp; font-size: 18px;&nbsp; color: white;&nbsp; display: block;}/* Style links on mouse-over */.sidebar a:hover {&nbsp; color: #f1f1f1;}/* Style the main content */.main {&nbsp; margin-left: 160px;&nbsp; /* Same as the width of the sidenav */&nbsp; padding: 0px 10px;}/* Add media queries for small screens (when the height of the screen is less than 450px, add a smaller padding and font-size) */@media screen and (max-height: 450px) {&nbsp; .sidebar {&nbsp; &nbsp; padding-top: 15px;&nbsp; }&nbsp; .sidebar a {&nbsp; &nbsp; font-size: 18px;&nbsp; }}<nav class="navbar navbar-inverse" nav id="nav_bar">&nbsp; <div class="container-fluid">&nbsp; &nbsp; <div class="navbar-header">&nbsp; &nbsp; &nbsp; <a class="navbar-brand" href="index.php"> MRB Data Library </a>&nbsp; &nbsp; </div>&nbsp; &nbsp; <ul class="nav navbar-nav">&nbsp; &nbsp; &nbsp; <li class="active"><a href="#" style=>Cars</a></li>&nbsp; &nbsp; &nbsp; <li class="active"><a href="#">||</a></li>&nbsp; &nbsp; &nbsp; <li class="active"><a href="#">Motorcycle</a></li>&nbsp; &nbsp; </ul>&nbsp; </div></nav><form action="slider_update.php" method="POST">&nbsp; <div class="sidebar">&nbsp; &nbsp; <center>&nbsp; &nbsp; &nbsp; <h2 style="color: white">LIBRARY</h2>&nbsp; &nbsp; </center>&nbsp; &nbsp; <a href="index.php"><i class="fa fa-fw fa-home"></i> Home</a>&nbsp; &nbsp; <a href="#.php"><i class="fa fa-fw fa-folder"></i> Reference</a>&nbsp; &nbsp; </nav>&nbsp; </div>
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答