I'm using Foundation for a project and I'm trying to add a small icon right before "SITENAME" in the top left corner. I've tried this css:
.top-bar .name h1 a:before {
background-image: url('images/logo.png');
background-size:18px 18px;
background-repeat: no-repeat;
}
but it doesn't seem to work. the image path is correct.
Here's the html:
<nav class="top-bar" id="mainmenu">
<ul class="title-area">
<li class="name">
<h1><a href="/site">SITENAME</a></h1>
</li>
<li class="toggle-topbar menu-icon"><a href="#"><span></span></a></li>
</ul>
<section class="top-bar-section">
</section>
</nav>
How can I add a simple icon/image without hacking into foundation.css?
Copy this tag <link rel="shortcut icon" href="images/favicon. ico" /> and past it without any changes in between <head> opening and </head> closing tag. Save changes in your html file and reload your browser.
So, in order to resolve this problem, we have assigned the display property of the image tag to “block” and then assign proper width and height to it. Assign the margin to “auto”. You will see that the logo image is now centered in the navigation bar.
If you are going to use the pseudo elements to show an image, you need to set content
to ''
(empty string), manually set the width
and height
, and set the display
to either inline
or inline-block
.
Like this:
.top-bar .name h1 a:before {
background-image: url('images/logo.png');
background-repeat: no-repeat;
content: "";
display: inline-block;
height: 18px;
margin-right: 10px;
position: relative;
width: 18px;
}
See a live demo here: http://plnkr.co/edit/ZeEBrfG2IchhqiNv5iWd?p=preview
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With