gpt4 book ai didi

html - IE7无法用边距抵消

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

谁能告诉我为什么我的以下代码在 IE7 中没有将“ block ”置于“枢轴”的中心?

相反,它似乎是那些浏览器“ block ”大小的一半。

<style>
.pivot {
position: absolute;
top: 50%;
left: 50%;
}
.block {
height: 200px;
width: 200px;

margin-left: -50%;
margin-top: -50%;

background-color: green;
}
</style>

<div class="pivot">
<div class="block"></div>
</div> <!-- end pivot -->

编辑

为了让它发挥作用,我使用了 IE6-IE-7 的 Erics 代码入侵了我对所有其他浏览器的 margin 方法

最佳答案

您的代码中有些地方是错误的,请尝试提供 pivot 宽度和高度,但它在任何浏览器中都不起作用。

如果你想让一个元素居中在屏幕的中央,你应该这样做:

#element {
width: 200px;
height: 200px;
position: absolute;
top: 50%;
left: 50%;
margin-left: -100px;
margin-top: -100px;
background-color: green;
}

它适用于所有浏览器,包括 IE6-7。

关于html - IE7无法用边距抵消,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8025752/

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