jquery - Overflow property in CSS -


.course_strip{      background-color: rgba(0,0,0,0.65);      height: 44px;      color:#f1f1f1;      line-height: 44px;      vertical-align: middle;      text-transform: uppercase;      font-size: 18px;      letter-spacing: 1px;      font-family: 'segoe ui';  }  .course_strip p{      padding: 0 10px;  }  .course_strip p:hover{      background-color: #000;  }  .course_strip p:active{      background-color: #4caf50;  }    .course_strip .glyphicon{      line-height: 44px;      top: 0px;  }  .course_strip_left p{      float: left;  }  .course_strip_right p{      float: right;  }  .left_container{      width: 20%;      height: 100%;      background-color: #f1f1f1;      padding-top: 20px;      padding-left: 16px;      font-family: 'segoe ui', tahoma, verdana, sans-serif;      font-size: 15px;  }  .left_container h2{      margin-top: -4px;      font-size: 21px;      font-weight: 500;  }  .left_container p{      margin-top: 40px;      padding-left: 1px;      font-weight: 500;  }
<html>  <head>      <title>tutorial</title>      <link rel="stylesheet" href="w3.css">      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">        <!-- jquery library -->      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>        <!-- latest compiled javascript -->      <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>  </head>  <body>      <div class="course_strip">          <div class="course_strip_left">              <p class="glyphicon glyphicon-home"></p>              <p>html</p>              <p>css</p>              <p>javascript</p>              <p>sql</p>          </div>          <div class="course_strip_right">              <p class="glyphicon glyphicon-search"></p>              <p class="glyphicon glyphicon-globe"></p>              <p>examples</p>              <p>references</p>          </div>      </div>      <div class="left_container">          <h2>html5 tutorial</h2>          <p>html home</p>          <p>html introduction</p>          <p>html editors</p>          <p>html basic</p>          <p>html elements</p>          <p>html attributes</p>          <p>html headings</p>          <p>html paragraphs</p>          <p>html styles</p>          <p>html formatting</p>          <p>html quotations</p>          <p>html comments</p>      </div>      <div class="right_container">      </div>  </body>  </html>

till here, fine me,

but if add, overflow-y: scroll .left_container class in css, left container shifts down bit, introducing strip of white background, not desired. unable find out why adding overflow property left_container shifting down. can please tell me why so? how can resolve it? thanks.

i don't know why, in specific example, adding overflow-y value other inerhit makes .left_container detach margin, know has block-level , visual formatting model.
applying overflow makes behave float:left would. if ever come across explain behavior, i'll here , update.


as far solutions go, easiest way achieve want wrap .left_container , .right_container in custom wrapper (i named .layout-wrapper below) , add existing css:

.layout-wrapper {   padding-left: 20%;   min-height: calc(100vh - 44px); } .layout-wrapper .left_container {   position: absolute;   left: 0;   width: 20%;   height: calc(100% - 44px);   overflow-y: auto; } 

notes:

  • you obtain same behavior position:fixed.
  • the same behavior can achieved flexbox , gives large array of options alignment , ordering. opted "classic" block level solution since has better support , else in example using same type of positioning.
  • i changed overflow-y:scroll auto that's matter of preference. can use scroll if prefer see bar.

here is, applied example:

.course_strip{      background-color: rgba(0,0,0,0.65);      height: 44px;      color:#f1f1f1;      line-height: 44px;      vertical-align: middle;      text-transform: uppercase;      font-size: 18px;      letter-spacing: 1px;      font-family: 'segoe ui';  }  .course_strip p{      padding: 0 10px;  }  .course_strip p:hover{      background-color: #000;  }  .course_strip p:active{      background-color: #4caf50;  }    .course_strip .glyphicon{      line-height: 44px;      top: 0px;  }  .course_strip_left p{      float: left;  }  .course_strip_right p{      float: right;  }  .left_container{      width: 20%;      height: 100%;      background-color: #f1f1f1;      padding-top: 20px;      padding-left: 16px;      font-family: 'segoe ui', tahoma, verdana, sans-serif;      font-size: 15px;  }  .left_container h2{      margin-top: -4px;      font-size: 21px;      font-weight: 500;  }  .left_container p{      margin-top: 40px;      padding-left: 1px;      font-weight: 500;  }      .layout-wrapper {    padding-left: 20%;    min-height: calc(100vh - 44px);  }  .layout-wrapper .left_container {    position: absolute;    left: 0;    width: 20%;    height: calc(100% - 44px);    overflow-y: auto;  }
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>        <div class="course_strip">          <div class="course_strip_left">              <p class="glyphicon glyphicon-home"></p>              <p>html</p>              <p>css</p>              <p>javascript</p>              <p>sql</p>          </div>          <div class="course_strip_right">              <p class="glyphicon glyphicon-search"></p>              <p class="glyphicon glyphicon-globe"></p>              <p>examples</p>              <p>references</p>          </div>      </div>      <div class="layout-wrapper">        <div class="left_container">          <h2>html5 tutorial</h2>          <p>html home</p>          <p>html introduction</p>          <p>html editors</p>          <p>html basic</p>          <p>html elements</p>          <p>html attributes</p>          <p>html headings</p>          <p>html paragraphs</p>          <p>html styles</p>          <p>html formatting</p>          <p>html quotations</p>          <p>html comments</p>        </div>        <div class="right_container">        </div>      </div>


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -