html - Vertically center align image in horizontal menu -
i want have image (my logo) in center of nav menu horizontal , @ top of page. far, each tag(including image) inside topnav div spreads evenly. want elements on either side of logo spread evenly want image in middle. perhaps should use 2 divs on same line , stick logo in middle?
here html
<div class="topnav" id="mytopnav" > <a href="home%20page.html">sustainability</a> <a href="environment.html">climate change</a> <img src="images/climate-hikewhite.png" height="50px" href="home%20page.html" /> <a href="diy.html">help @ home</a> <a href="contact.html">contact us</a> </div>
here css
/*navigation bar */ /* add black background color top navigation */ .topnav { background-color: #000; overflow: hidden; list-style: none; margin: 0; padding-top: 5px; padding-bottom: 5px; display: flex; justify-content: space-around; text-decoration: none; font-size: 24px; color: #000; width: 100%; } /* style links inside navigation bar */ .topnav { list-style: none; margin: 0 2px; padding-top: 10px; padding-bottom: 5px; display: flex; justify-content: space-around; text-decoration: none; font-size: 17px; color: #eee; font-family: 'lucida sans unicode', 'lucida grande', sans-serif; } .titletext { list-style: none; margin: 0 2px; padding-top: 10px; padding-bottom: 5px; display: flex; justify-content: space-around; text-decoration: none; font-size: 17px; color: #fff; font-family: papyrus, fantasy; } /* change color of links on hover */ .topnav a:hover { background-color: #000; color: green; } /* add color active/current link */ .topnav a.active { background-color: #4caf50; color: white; }
ok, think know you're saying. trying anchor elements aren't vertically centered on .topnav? if so, should add align-items: center
to .topnav css styles. .topnav css should this:
.topnav { background-color: #000; overflow: hidden; enter code here list-style: none; margin: 0; padding-top: 5px; padding-bottom: 5px; display: flex; justify-content: space-around; text-decoration: none; font-size: 24px; color: #000; width: 100%; align-items: center; }
you can read more align-items
here: https://css-tricks.com/almanac/properties/a/align-items/
Comments
Post a Comment