垂直对齐,给我同样的头痛

时间:2014-01-28 12:03:59

标签: html css vertical-alignment

嗨我试图在h1中垂直对齐锚文本,我试过垂直对齐中间和几行高度技巧不能让它工作!

<header>
<div></div>
<h1><a>somelink</a></h1>
</header>

的CSS:

div{
height:80px;
width:80px;
float:left;
}

h1{
      font-size: 32px;
      line-height: 32px;
      min-height: 80px;
      vertical-align: middle;
      a{
        line-height: inherit;
        vertical-align: middle;
      }

这是我的目标,我可以用表解决它,但是关于是否应该使用表格以及我试图寻找替代方案的争论很多:

enter image description here

1 个答案:

答案 0 :(得分:1)

DEMO

您可以为此添加一个parent div: -

 <div id="parent">
    <div id="child"></div>        
    <h1><a>somelink is here.somelink is here.somelink is here.somelink is here.somelink is here.somelink is here.somelink is here.somelink is here.</a></h1>
 </div>

CSS

#child {
    height:200px;
    width:80px;
    float:left;
    background: #333333;
}
#parent{
    border:solid 1px yellow;
    width: 100%;