CSS 侧边栏始终全高

  • 本文关键字:侧边栏 CSS html css
  • 更新时间 :
  • 英文 :


我正忙于此页面(http://s.nogax.ga/editor-css.html),我正在尝试制作一个全高侧边栏。基本上,div 侧边栏应始终延伸到屏幕底部。(以及它右侧的黑线)

JSFiddle

.html

  <div class='main-nav'>
    Site Name Editor
  </div>
  <div class='content'>
    <div class='sidebar'>
      Page Names
    </div>
    <div class='editor'>
      Optie 1 <br>
      Optie 2 <br>
    </div>
  </div>

.css

html, body {
  background-color: grey;
  margin-top: 0;
  margin-bottom: 0;
  margin-left: 0;
  margin-right: 0;
  heigth: 100%;
}
.main-nav {
  background-color: black;
  color: white;
  font-family: 'Noto Sans', sans-serif;
  font-size: 150%;
  heigth: 20px;
  margin-top: 0;
  margin-bottom: 0;
  margin-right: 0;
}
.content {
  position: absolute;
  width: 100%;
  heigth: 100%;
}
.sidebar {
  width: 15%;
  position: absolute;
  background-color: grey;
  border-right: 2px solid;
}
.editor {
  position: absolute;
  width: 84.5%;
  right: 0;
  background-color: grey;
}
如果您希望

侧边栏始终显示在侧面,则可以将其设为position:fixed

.sidebar {
   height: 100%;
   position: fixed;
}

这是一个例子

应用以下 css 将按预期进行输出:

.sidebar {
  width: 15%;
  position: fixed;
  background-color: grey;
  border-right: 2px solid;
    bottom:0;
}

检查 https://jsfiddle.net/r8u7pkd6/2/。

对于信息和现在的浏览器,您也可以使用display:flex;

顺便说一句:你打错了 height != heigth

@font-face {
  font-family: 'Noto Sans';
  font-style: normal;
  font-weight: 400;
  src: local('Noto Sans'), local('NotoSans'), url(http://fonts.gstatic.com/s/notosans/v6/LeFlHvsZjXu2c3ZRgBq9nFtXRa8TVwTICgirnJhmVJw.woff2) format('woff2'), url(http://fonts.gstatic.com/s/notosans/v6/LeFlHvsZjXu2c3ZRgBq9nD8E0i7KZn-EPnyo3HZu7kw.woff) format('woff');
}
    html, body {
      background-color: grey;
      margin: 0;
      width :100%;
      height:100%;
      flex-direction:column
    }
    body,.content {
     display:flex;
    }
    .main-nav {
      background-color: black;
      color: white;
      font-family: 'Noto Sans', sans-serif;
      font-size: 150%;
      margin: 0;
    }
    .content {
      flex:1;
    }
    .sidebar {
      width: 15%;
      background-color: grey;
      border-right: 2px solid;
    }
    .editor {
      flex:1; /* will use remaining space*/
      /*width: 84.5%;
      right: 0; useless here*/
      background-color: lightgrey;
    }
  
  <div class='main-nav'>
    Site Name Editor
  </div>
  <div class='content'>
    <div class='sidebar'>
      Page Names
    </div>
    <div class='editor'>
      Optie 1 <br>
      Optie 2 <br>
    </div>
  </div>

最新更新