I want the Logo Image in this nav-bar to fill its height while still retaining its aspect ratio. The remaining width should be filled by the ul element.
As long as the ul elements width is not 100% the image is displayed correctly.
How can I do that?
The Code:
<div id="navbar">
<div id="logoBox">
<img src="http://i.imgur.com/wuRN2wD.png" id="logo">
</div>
<ul>
<li>
<a href="#fakelink">
Item 1
</a>
</li>
<li>
<a href="#fakelink">
Item 2
</a>
</li>
<li>
<a href="#fakelink">
Item 3
</a>
</li>
<li>
<a href="#fakelink">
Item 4
</a>
</li>
<li>
<a href="#fakelink">
Item 5
</a>
</li>
</ul>
#navbar {
display: flex;
width: 80%;
height: 3.8em;
margin-top: 4em;
margin-left: auto;
margin-right: auto;
background: #f39c12;
}
#logoBox {
display: inline-block;
*display: inline;
height: 100%;
float: left;
margin-left: 1%;
}
#logo {
max-height: 100%;
max-width: 100%;
}
#navbar ul {
display: inline-block;
white-space: nowrap;
vertical-align: top;
overflow: hidden;
width: 100%;
height: 100%;
right: 0;
margin: 0;
padding: 0;
}
#navbar li {
display: inline-block;
padding-left: 4%;
margin-top: 1.9em;
line-height: 0;
}
#navbar a {
color: #FFFFFF;
text-decoration: none;
font-size: 1.25em;
}
Your current issue is in the
#logoattributes -max-widthandmax-heightwon't actually expand the div unless there is content inside that forces it to expand. Also, you'll want to set thebackground-size = coverso the aspect ratio is maintained.Try this instead:
#logo { max-height: 100%; height: 100%; background-size: cover; }