Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS Sidebar always full height

Tags:

html

css

I am busy on this page (http://s.nogax.ga/editor-css.html) and I am trying to make a full height sidebar. Basically, the div sidebar should always extend to the bottom of your screen. (and with it the black line on the right of it)

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;
}
like image 660
Rumanoid Avatar asked Dec 08 '25 05:12

Rumanoid


2 Answers

You can just make the sidebar position:fixed if you want it to always be displayed on the side:

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

Here is an example

like image 191
Antonio Smoljan Avatar answered Dec 10 '25 23:12

Antonio Smoljan


Apply following css will make output as you expected:

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

Check https://jsfiddle.net/r8u7pkd6/2/.

like image 33
ketan Avatar answered Dec 11 '25 00:12

ketan