The height of a block element defaults to the height of the block's
content. So, given something like this:
<div id="outer">
<div id="inner">
<p>Where is pancakes house?</p>
</div>
</div>
#inner
will grow to be tall enough to contain the paragraph and
#outer
will grow to be tall enough to contain #inner
.
When you specify the height or width as a percentage, that's a
percentage with respect to the element's parent. In the case of width,
all block elements are, unless specified otherwise, as wide as their
parent all the way back up to <html>
; so, the width of a block
element is independent of its content and saying width: 50%
yields a
well defined number of pixels.
However, the height of a block element depends on its content
unless you specify a specific height. So there is feedback between the
parent and child where height is concerned and saying height: 50%
doesn't yield a well defined value unless you break the feedback loop
by giving the parent element a specific height.
The credits of the above are for @muistooshort: https://stackoverflow.com/a/5658062/4966662
I guess you want set the height of each li
to vertical align the menu, if I'm right, here you have a workaround using flexbox:
body{
margin: 0;
}
.main-navigation {
background-color: #fff;
margin-left: auto;
margin-right: auto;
-webkit-box-shadow: 3px 2px 2px 0px rgba(0, 0, 0, 0.75);
-moz-box-shadow: 3px 2px 2px 0px rgba(0, 0, 0, 0.75);
box-shadow: 3px 2px 2px 0px rgba(0, 0, 0, 0.75);
margin-bottom: 4px;
}
#middleNavigation {
margin-left: auto;
margin-right: auto;
width: 960px;
display: flex;
}
.main-navigation a {
font-size: 1.4rem;
font-size: 14px;
font-weight: normal;
margin-left: 1em;
text-decoration: none;
padding: 0 0.8em;
word-spacing: 4px;
font-family: Arial;
color: #000;
border-top: 4px solid transparent;
display: flex;
align-items: center;
}
.main-navigation a:hover {
border-top-color: #000;
}
<nav role="navigation" class="site-navigation main-navigation">
<div id="middleNavigation">
<img src="http://notthedroidyouarelookingfor.com/wp-content/themes/striker/images/NTDYALF-Logo.png" alt="" id="NTDYALFLogo">
<a href="http://notthedroidyouarelookingfor.com/"><span>Home</span></a>
<a href="http://notthedroidyouarelookingfor.com/index.php/sample-page/"><span>Sample Page</span></a>
</div>
</nav>
<p>Hover the links to see the border</p>
Here a working JSFiddle to play with