html - Border of child element affects div size of the parent -


i made when hover item in menu, there comes little line underneath with: border-bottom: 2px;. when hover item in menu parent element (the header in case) grow 2px on bottom.

my html code:

<div class="header">       <nav class="navigation_menu">              <ul class="navigation_ul">                  <a href="#"><li>lorum</li></a>                 <a href="#"><li>ipsum</li></a>                 <a href="#"><li>lorpsum</li></a>                 <a href="#"><li>ipum</li></a>                 <a href="#"><li>nadoa</li></a>              </ul>      </nav>  </div> 

my css code:

body {     background:f5f5f5;     margin: 0px;     padding: 0px;     font-family: roboto; }  /** text style **/  {     text-decoration: none;     color: inherit; }  /** header style **/  .header {     background: #607d8b;     margin: 0px;     padding: 10px;     padding-bottom: 50px;     color: white; }  /** navigation menu style **/  .navigation_menu ul {     margin: 0px;     padding: 0px;     overflow: hidden; }  .navigation_menu li {     font-size:18px; }  .navigation_menu li:hover {     border-bottom: 2px solid white; }  .navigation_menu ul li {     display: inline-block;     padding: 0px 0px; } 

and here sample: http://codepen.io/anon/pen/rvjjqw

i hope can find answer here! in advance!

the problem border occupies space, parent grows.

instead, can consider setting transparent border , changing color @ hover:

.navigation_menu li {   border-bottom: 2px solid transparent; } .navigation_menu li:hover {   border-bottom-color: white; } 

/** general style **/  body {    background: f5f5f5;    margin: 0px;    padding: 0px;    font-family: roboto;  }    /** text style **/  {    text-decoration: none;    color: inherit;  }    /** header style **/  .header {    background: #607d8b;    margin: 0px;    padding: 10px;    padding-bottom: 50px;    color: white;  }    /** navigation menu style **/  .navigation_menu ul {    margin: 0px;    padding: 0px;    overflow: hidden;  }  .navigation_menu li {    font-size:18px;    border-bottom: 2px solid transparent;  }  .navigation_menu li:hover {    border-bottom-color: white;  }  .navigation_menu ul li {    display: inline-block;    padding: 0px 0px;  }
<div class="header">     <nav class="navigation_menu">      <ul class="navigation_ul">        <a href="#"><li>lorum</li></a>        <a href="#"><li>ipsum</li></a>        <a href="#"><li>lorpsum</li></a>        <a href="#"><li>ipum</li></a>        <a href="#"><li>nadoa</li></a>      </ul>    </nav>  </div>


Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -