0
<div class="cn_header">
    <div class="print"></div>
    example
</div>​

.cn_header{
    background: #C2E1FF;
    height: 24px;
    line-height: 24px;
    padding: 5px;
}

.print{
    background: url(http://mcgrefer.com/images/search.png);
    display: inline-block;
    height: 24px;
    width: 24px;
}
​

http://jsfiddle.net/Luntegg/2SCvf/1/

如何使用背景图像和文本设置内联 div?

4

2 回答 2

2

设置vertical-align:middle;.print

演示

于 2012-12-13T11:22:11.003 回答
0

将文本放入 div 中:

http://jsfiddle.net/2SCvf/3/

<div class="cn_header">
    <div class="print">example</div>
</div>


.cn_header{
    background: #C2E1FF;
    height: 24px;
    line-height: 24px;
    padding: 5px;    
}

.print{
    background-image: url(http://mcgrefer.com/images/search.png);
    display: inline-block;
    height: 24px;
    width: 24px;
    padding-left: 30px; /* This */
    background-repeat: no-repeat; /* And This One */
}
于 2012-12-13T11:22:43.467 回答