gpt4 book ai didi

html - 在 IE7 中垂直对齐父 DIV 中的 DIV

转载 作者:太空宇宙 更新时间:2023-11-04 15:33:40 26 4
gpt4 key购买 nike

想知道是否可以在父 DIV 中垂直对齐 X 个 DIV。

所有的 DIV 都没有固定的高度。

在除 IE7 之外的所有浏览器中工作。

illustrated example

<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+支持

Check its Compatibility

编辑:

作为解决方法,您可以选择 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();
//
});

Refer this post

关于html - 在 IE7 中垂直对齐父 DIV 中的 DIV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13062753/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com