gpt4 book ai didi

html - 如何在 div 元素内水平居中图像?

转载 作者:行者123 更新时间:2023-11-28 05:59:43 25 4
gpt4 key购买 nike

如何在其容器 div 内居中对齐(水平)图像?

这是 HTML 和 CSS。我还包含了缩略图其他元素的 CSS。它按降序运行,因此最高的元素是所有内容的容器,最低的元素在所有内容中。

#thumbnailwrapper {
color: #2A2A2A;
margin-right: 5px;
border-radius: 0.2em;
margin-bottom: 5px;
background-color: #E9F7FE;
padding: 5px;
border: thin solid #DADADA;
font-size: 15px
}

#artiststhumbnail {
width: 120px;
height: 108px;
overflow: hidden;
border: thin solid #DADADA;
background-color: white;
}

#artiststhumbnail:hover {
left: 50px
}
<!--link here-->

<a href="NotByDesign">
<div id="thumbnailwrapper">

<a href="NotByDesign">

<!--name here-->
<b>Not By Design</b>
<br>

<div id="artiststhumbnail">

<a href="NotByDesign">

<!--image here-->
<img src="../files/noprofile.jpg" height="100%" alt="Not By Design" border="1" />
</a>
</div>

<div id="genre">Punk</div>

</div>

好的,我已经添加了没有 PHP 的标记,所以应该更容易看到。这两种解决方案在实践中似乎都行不通。顶部和底部的文本不能居中,图像应在其容器 div 中居中。容器已 overflow hidden ,所以我想看到图像的中心,因为通常焦点所在的位置。

最佳答案

#artiststhumbnail a img {
display:block;
margin:auto;
}

这是我的解决方案:http://jsfiddle.net/marvo/3k3CC/2/

关于html - 如何在 div 元素内水平居中图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36828125/

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