【发布时间】:2014-08-25 15:49:11
【问题描述】:
使用CSS 将#dates div 与标题的右侧对齐,并在中间垂直对齐,什么是最好/最干净的。
我尝试了float: right,但这不允许vertical-align。我想避免使用浮点数,所以我使用inline-block,并使用相对定位。有没有更正确的做法?
我不喜欢我必须做一个 30px 的顶部,并使用反复试验直到它居中。
<div id="header">
<a id="logo" href="~/" runat="server">
<img src="Images/Interface/logo.png" alt="logo" />
</a>
<div id="dates">
<div id="hijri-date">2 Ramadhaan, 1435 AH</div>
<div id="gregorian-date">Sunday 29 June 2014</div>
</div>
</div>
#header
{
background-color: white;
padding: 15px;
position: relative;
}
#logo
{
display: inline-block;
vertical-align: middle;
}
#logo img
{
vertical-align: bottom; /* to get rid of text descender space underneath image */
}
#dates
{
display: inline-block;
position: absolute;
right: 30px;
top: 30px;
font-size: 14px;
font-family: 'Open Sans';
color: #696969;
background: url(Images/Interface/date-icon.png) no-repeat;
background-position-y: center;
padding-left: 32px;
}
【问题讨论】:
标签: html alignment vertical-alignment css