将文本垂直居中对齐h2标签的背景 [英] Align text vertically center of h2 tag with a background

查看:631
本文介绍了将文本垂直居中对齐h2标签的背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个h2标签,其背景图片为图标。我想在h2标签内垂直对齐文本,但它不工作。我尝试使用 display:table-cell; 但是没有工作。文本也可以跨两行。

I have a h2 tag that has a background image as an icon. I want to align the text vertically within the h2 tag but it doesn't work. I have tried using the display: table-cell; but that hasn't worked either. The text may also crossover onto two lines.

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/

JSFiddle Example: http://jsfiddle.net/YPnTp/

推荐答案

更改您的


.FeatureRow h2,添加 line-height

css如下

.FeatureRow h2{
background-repeat: no-repeat;
padding-left: 65px;
font-size: 22px;
height: auto;
min-height: 60px;
color: #3F92ED;
line-height:2.5em;
}

这篇关于将文本垂直居中对齐h2标签的背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆