什么是使用CSS将#dates div对齐到头部右侧并垂直居中的最佳/最干净方法?
我尝试了float: right,但这样无法使用vertical-align。我想避免使用floats,因此我使用inline-block,并使用相对定位。是否有更正确的方法?
我不喜欢必须做一个30px的顶部,然后不断尝试使其居中。
我尝试了float: right,但这样无法使用vertical-align。我想避免使用floats,因此我使用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;
}