0

我有一个带有背景图像作为图标的 h2 标签。我想在 h2 标签内垂直对齐文本,但它不起作用。我尝试过使用,display: table-cell;但也没有用。文本也可以交叉到两行。

HTML:

<ul class="FeatureRow">
    <li><a href="#"><span><h2 class="SpeechBg">Need some help?</h2><p>Feel free to get in contact with us</p></span></a></li>
    <li><a href="#"><span><h2 class="PinBg">Great locations!</h2></span></a></li>
    <li><a href="#"><span><h2 class="ViewBg">View our apartments</h2></span></a></li>
</ul>

CSS:

a {
color: #2b6893;
text-decoration: none;
}
.FeatureRow{
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
}
.FeatureRow li{
float: left;
padding: 10px;
margin: 10px;
height: auto;
-webkit-box-shadow: 0px 4px 8px #f5f5f5;
-moz-box-shadow: 0px 4px 8px #f5f5f5;
box-shadow: 0px 4px 8px #f5f5f5;
background-color: #fdfdfd;
background-image: -moz-linear-gradient(top,#fbfbfb,#ffffff);
background-image: -webkit-gradient(linear,0 0,0 100%,from(#fbfbfb),to(#ffffff));
background-image: -webkit-linear-gradient(top,#fbfbfb,#ffffff);
background-image: -o-linear-gradient(top,#fbfbfb,#ffffff);
background-image: linear-gradient(to bottom,#fbfbfb,#ffffff);
background-repeat: repeat-x;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#fffbfbfb',endColorstr='#ffffffff',GradientType=0);
filter: progid:DXImageTransform.Microsoft.gradient(enabled= false);
}
.FeatureRow span{
display: block;
width: 260px;
}
.FeatureRow h2{
background-repeat: no-repeat;
padding-left: 65px;
font-size: 22px;
height: auto;
min-height: 60px;
color: #3F92ED;
}
.SpeechBg{
background-image: url(http://joshblease.co.uk/Apartments/images/icons/speech.png);
}
.PinBg{
background-image: url(http://joshblease.co.uk/Apartments/images/icons/pin.png);
}
.ViewBg{
background-image: url(http://joshblease.co.uk/Apartments/images/icons/view.png);
}

JSFiddle 示例:http: //jsfiddle.net/YPnTp/

4

2 回答 2

2

改变你的

.FeatureRow h2 ,添加行高

css如下

.FeatureRow h2{
background-repeat: no-repeat;
padding-left: 65px;
font-size: 22px;
height: auto;
min-height: 60px;
color: #3F92ED;
line-height:2.5em;
}
于 2013-07-30T16:03:04.833 回答
1

.SpeechBg.PinBg.ViewBg中,添加line-height: ##px;,其中 ## 是背景图像的高度(以 px 为单位)。

于 2013-07-30T16:01:08.883 回答