<header id="logo">
<img src="logo.png" />
<h1>Some text here</h1>
</header>
我使用
h1{display: inline;}
为了使它们在同一行,但文本低于图像, 图片大小为48x48px,文本大小为23px,我想将文本垂直居中到图像上,如何使用CSS实现?只需要支持Chrome。
谢谢你的回答,最终成功了:http://jsfiddle.net/tFdpW/
<header id="logo">
<img src="logo.png" />
<h1>Some text here</h1>
</header>
我使用
h1{display: inline;}
这样做可以吗?http://jsfiddle.net/xs4x6/
<header id="logo">
<img src="http://dummyimage.com/48x48/f0f/fff" />
<h1>Some text here</h1>
</header>
header img {
vertical-align: top
}
h1 {
display: inline;
font-size: 23px;
line-height: 48px
}
margin:0 8px 8px 0;
。 - Floernh1{display: inline;line-height:48px;}
@wong2; 首先,inline
属性不支持垂直边距和填充属性。因此,还有其他选项。
第一步:移除 display:inline
并为其添加 float
。
img, h1{float:left;}
h1{margintop:15px; margin-left:10px;}
display:table
应用于它。#logo{display:table}
img, h1{display:table-cell}
h1{vertical-align:middle;}
display:inline
。h1{display: inline;line-height:48px;}
vertical-align:middle
属性。
尝试使用
h1 {
display: table-cell;
vertical-align: middle;
}