使用Zurb的基础4在导航栏中添加站点标题/徽标之前的图像/图标

kar*_*gen 5 html css icons title zurb-foundation

我正在使用Foundation进行项目,我正试图在左上角的"SITENAME"之前添加一个小图标.我试过这个css:

.top-bar .name h1 a:before {
    background-image: url('images/logo.png');
    background-size:18px 18px;
    background-repeat: no-repeat;

}
Run Code Online (Sandbox Code Playgroud)

但它似乎没有用.图像路径是正确的.

这是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>
Run Code Online (Sandbox Code Playgroud)

如何在不侵入foundation.css的情况下添加简单的图标/图像?

chr*_*s-l 5

如果要使用伪元素显示图像,则需要设置content''(空字符串),手动设置widthheight,并将其设置displayinline或者inline-block.

像这样:

.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;
}
Run Code Online (Sandbox Code Playgroud)

观看现场演示:http://plnkr.co/edit/ZeEBrfG2IchhqiNv5iWd?p =preview