gpt4 book ai didi

css - 如何在
中水平和垂直居中

转载 作者:搜寻专家 更新时间:2023-10-31 23:13:49 24 4
gpt4 key购买 nike

我不想让div居中,我想让div的内容居中。我想要水平和垂直对齐方式。

抱歉,如果这太简单或其他原因,但要做到这一点有点麻烦。

格雷

我正在使用 IE7

最佳答案

如果您知道图像的高度和宽度,请将其绝对定位,将 top/left 设置为 50% 并将 margin-top/left 设置为图像高度/宽度的一半negative

#foo {
position:relative; /* Ensure that this is a positioned parent */
}
#foo img {
width:240px;
height:200px;
position:absolute;
left:50%;
top:50%;
margin-left:-120px;
margin-top:-100px;
}

实例:http://jsfiddle.net/Zd2pz/

关于css - 如何在 <div> 中水平和垂直居中 <img>?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4494130/

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