[英]Vertical align DIVs within Parent DIV in IE7
想知道是否可以在父DIV中垂直对齐X个DIV。
所有DIV都没有固定高度。
在除IE7之外的所有浏览器中均可使用。
<div class="parent">
<div class="left">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ac faucibus nisi. Proin nec eros est, vitae rhoncus purus.
</div>
<div class="right">
<img src="image.gif" width="50" height="50">
</div>
</div>
.parent {
display: table;
vertical-align: middle;
}
.left, .right {
display: table-cell;
vertical-align: middle;
}
IE7不支持display: table-cell;
属性,它已获得IE8 +的支持
编辑:
作为解决方法,您可以选择jQuery-
$(function() {
// vertical align function
$.fn.vAlign = function() {
return this.each(function(i){
var ah = $(this).height();
var ph = $(this).parent().height();
var mh = Math.ceil((ph-ah) / 2); //var mh = (ph - ah) / 2;
$(this).css('margin-top', mh);
});
};
$('.greenBorder img').vAlign();
//
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.