【发布时间】:2014-01-16 04:22:58
【问题描述】:
我试图弄清楚如何垂直对齐 2 个浮动 div。每个 div 都有一个灵活的高度。
这是我目前所拥有的:http://jsfiddle.net/VLRpc/1/
<div class="section">
<div class="container">
<div class="wrap">
<div class="column left">
<h1>Software</h1>
<p>I use many software applications to achieve the best results.</p>
</div>
<div class="column right"></div>
</div><!-- end wrap -->
</div><!-- end container -->
</div><!-- end section -->
.container {
width: 100%;
height: 100%;
display: table;
position: absolute;
top: 0;
left: 0;
margin: 0;
padding: 0;
}
.wrap {
vertical-align: middle;
display: table-cell;
padding: 0;
margin: 0;
border: 1px solid red;
}
/* Columns */
.column {
width: 45%;
height: auto;
float:left;
text-align: center;
border: 1px solid black;
}
.right {
margin-left:0;
height: 250px
}
.left {
margin-left:5%;
}
但是,左侧的 div 被推到右侧较大 div 的顶部。我需要将这两个 div 垂直居中。
有什么想法吗?
【问题讨论】:
-
absolute 或 float 会杀死任何显示值,或者您使用 display(table/table-cell - inline-block ) 来垂直对齐,或者使用具有有趣负边距的 absolute 或 float :),我猜你会得到我的选择:)
-
你能提供一个jsfiddle的例子吗?
-
jsfiddle.net/VLRpc/3 是这样的吗?
-
还是这样? jsfiddle.net/VLRpc/4
-
是的,在列类上使用 display:inline 和垂直对齐中间就可以了
标签: css css-float vertical-alignment