html - CSS Padding is overflowing parent -


i'm trying make horizontal navbar, , i've got sitting @ top of page each of 3 list items filling third of space, on part.

the issue when try make anchor tag (which within list item) fill of list item's space. set display: block;, takes full width, can't fill vertical space how want to. can use height: 100% , fill space, if way anchor tag's text rests @ top of list item's space, want vertically centred. top , bottom padding came mind this, tried setting padding: 100%;. when happened, no longer see text of anchor tag. dragging space mouse looks tag taking more space in list item.

this image of nav bar height: 100%;: nav bar note: red lines surrounding each section borders set visible view boundaries

the relevant html code follows:

<ul class="main_nav">     <li><a href="#">home</a></li>     <li><a href="#">test page</a></li>     <li><a href="#">test page 2</a></li> </ul> 

the relevant css code follows:

body * {     font-family: roboto sans-serif;      box-sizing: border-box;      border: solid 2px red; }  header ul.main_nav {     background-color: gray;     color: #ebebeb;      margin: 0px;      padding: 0px;      width: 100%;     height: 50px;      list-style-type: none;     list-style-position: inside;      overflow: hidden; }  header ul.main_nav li {     text-align: center;      float: left;      width: calc(100% / 3);     height: 100%; }  header ul.main_nav li {     display: block;      height: 100%;      text-decoration: none; } 

edit: rather not use fixed sizes solve this, i'd largely prefer being able edit single value (50px ul) adjust whole navbar

you can using flexbox,

*,  *:before,  *::after {    box-sizing: border-box;  }  body * {    font-family: roboto sans-serif;    border: solid 2px red;  }  ul.main_nav {    background-color: gray;    color: #ebebeb;    margin: 0;    padding: 0;    width: 100%;    height: 50px;    list-style-type: none;    list-style-position: inside;    display: flex  }  ul.main_nav li {    flex: 1;    display: flex;    height:100%;  }  ul.main_nav li {   flex: 1;    display: flex;    justify-content: center;    align-items: center;    background: yellow  }
<ul class="main_nav">    <li><a href="#">home</a>    </li>    <li><a href="#">test page</a>    </li>    <li><a href="#">test page 2</a>    </li>  </ul>

if going have 1 line only in menu, yo can use line-height, see below

*,  *:before,  *::after {    box-sizing: border-box;  }  body * {    font-family: roboto sans-serif;    border: solid 2px red;  }  ul.main_nav {    background-color: gray;    color: #ebebeb;    margin: 0;    padding: 0;    width: 100%;    height: 50px;    list-style-type: none;    list-style-position: inside;    overflow: hidden;    font-size: 0;  }  ul.main_nav li {    text-align: center;    width: calc(100% / 3);    height: 100%;    display: inline-block;    font-size: 16px  }  ul.main_nav li {    display: block;    height: inherit;    background: yellow;    text-decoration: none;    line-height: 32px /*this should same value has parent height*/  }
<ul class="main_nav">    <li><a href="#">home</a>    </li>    <li><a href="#">test page</a>    </li>    <li><a href="#">test page 2</a>    </li>  </ul>


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -