html - Have child item fill parent using flexbox -


i have navigation have child elements (in case: tags) fill height of flex parent (ul). possible not use padding , solely rely on flexbox here? appreciated here. can see in codepen, black tags not fill area. eventual plan add border @ top when tag hovered. why need fill area. want use flexbox instead of padding if possible.

this have far:

<div class="nav"> <ul>     <li><a href="#">link</a></li>     <li><a href="#">link</a></li>     <li><a href="#">link</a></li>     <li><a href="#">link</a></li>     <li><a href="#">link</a></li> </ul> 

body, html { background:skyblue; padding:0; margin:0; } .nav {     background-color:salmon;     height:40px;     ul          { display:flex; align-items:center; height:100%; }     ul > li     { list-style:none; background:black; flex:1; }     ul > li > {  } } 

https://codepen.io/jesders88/pen/gvqgzx

the <a> tags indeed taking full height of parent <li> elements -- forgot state <li> elements should take 100% of height of <ul> element.

adding height: 100% .nav ul > li causes <a> tags take full height of <ul>, in seen in codepen i've created here.

note adding height: 100% causes <a> tags displayed flush against top of navbar. if want both vertically , horizontally center <a> tags in expanded navbar, can making <li> elements flexbox themselves, , utilising align-items , justify-content:

.nav ul > li {   display: flex;   align-items: center;   justify-content: center; } 

i've created secondary codepen showcasing here.

hope helps!


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -