如何使菜单链接在文本旁边有图像?

时间:2013-10-15 19:23:33

标签: css image menu hyperlink

像这样:http://html5up.net/strongly-typed/ 如果您查看菜单,每个菜单链接旁边都会显示这些小圆圈。 我到底该怎么做?

#menu a {
text-decoration: none;
font-family: "Open Sans", Helvetica, arial;
font-size: 14px;
font-weight: bold;
text-transform: uppercase;
color: #EEE;
line-height: 1;
margin-right: 45px;
text-shadow: 1px 2px 0 #111;
text-align: center;

这是我到目前为止获得菜单链接的代码,但是当我尝试添加这些小圆圈时它只是不起作用:/什么都没有出现,如果有东西出现,那么它1)不是圆圈2)不在链接旁边。

帮助:/

2 个答案:

答案 0 :(得分:1)

使用background-image:before伪选择器的组合。

这是一个非常简单的例子。

jsFiddle here

<强> CSS

li:before {
    content: "\A";
    background: url('http://placehold.it/30x30') no-repeat 0px 0px / 30px 30px;
    padding: 8px 20px;
}

答案 1 :(得分:0)

使用firebug或chrome的检查器检查元素,您会看到代码:

#nav > ul > li > a:before {
    display: inline-block;
    background: #878787;
    color: #e4e4e4;
    width: 1.65em; 
    height: 1.65em;
    border-radius: 1.65em;
    line-height: 1.65em;
    text-align: center;
    box-shadow: 0.125em 0.175em 0 0 rgba(0,0,0,0.125);
    margin-right: 0.75em;
    -webkit-transition: color 0.25s ease-in-out, background 0.25s ease-in-out;
    -moz-transition: color 0.25s ease-in-out, background 0.25s ease-in-out;
    -ms-transition: color 0.25s ease-in-out, background 0.25s ease-in-out;
    -o-transition: color 0.25s ease-in-out, background 0.25s ease-in-out;
    transition: color 0.25s ease-in-out, background 0.25s ease-in-out;
}

CSS seletor ':在之前在对象之前插入元素“#nav&gt; ul&gt; li&gt; a”

hacks ' - moz - ',' - webkit - ',' - o - '和'-ms - '是使代码跨浏览器。