我正在尝试垂直对齐标题中的文本,但遇到了一些问题。以下是我的起点图片:
标题的高度为141px,标题中的所有内容都应该居中。即使是"Name of Website Here",如果名称更改并且只占据1行或者3行,它仍将位于同一位置。
注意:这适用于多个网站,这些网站是动态生成的,因此无法使用margin-top
来定位,因为名称将不同,有些可能占用几行,而有些可能占用多行。
出于搜索在线解决方案的目的,我删除了垂直对齐文本的尝试代码,因为没有任何效果。以下是我的起点代码:
HTML:
<div id="header">
<h1>Name of Website Here</h1>
<h3>Call Today!<br /><span>(xxx) xxx-xxxx</span></h3>
<p>123 Main St.<br />City, State, Zip</p>
</div>
CSS:
#header{height:141px;}
#header h1{float:left;font-size:1.7em;width:200px;text-align:center;line-height:26px}
#header h3{float:left;text-align:center;color:#e62520;font-size:1.7em;line-height:26px;font-style:italic;margin:0 0 0 95px}
#header h3 span{font-size:1.2em;}
#header p{float:right;color:#2a5091;font-size:1.3em;font-style:italic;font-weight:bold;line-height:20px;text-align:right;}
谢谢!
display:inline-block
或display:table-cell
来使其工作,但你可能会遇到一些 IE6/7 的问题。 - sdleihssirhc