gpt4 book ai didi

html - 如何将 img 居中放置在 div 中

转载 作者:行者123 更新时间:2023-11-28 06:08:35 24 4
gpt4 key购买 nike

我正在尝试一些应该很容易的事情,但我不知道如何去做。

我有这样的 html 源代码:

<div class="product">
<img src="product123.png" />
</div>`

还有一些CSS:

.product {
width: 460px;
height: 460px;
}

.product img {
margin: auto;
display: block;
}

我的图片水平对齐很好,但垂直对齐不正确。我尝试了一些 position: relative;/bottom: 0; 功能,但它没有改变任何东西......

有什么想法吗?

感谢您的帮助!

PS:我找到了这个解决方案 center <IMG/> inside a <DIV> with CSS但我宁愿保持我的 HTML 是这样的,而且不能以“我的”方式做到这一点似乎令人难以置信。

最佳答案

试试这个 - http://jsfiddle.net/tG9UK/

.product {
width: 460px;
height: 460px;

display: table-cell;
vertical-align: middle;
}

关于html - 如何将 img 居中放置在 div 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36311773/

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