gpt4 book ai didi

html - 溢出 :hidden div 内的垂直对齐图像

转载 作者:太空宇宙 更新时间:2023-11-04 13:51:56 25 4
gpt4 key购买 nike

我试图在 div 中垂直对齐图像,并将溢出设置为隐藏,以便每个帖子的容器具有相同的高度。我尝试了很多其他解决方案,但它不适用于溢出元素。有人吗?到目前为止,这是我的 CSS 代码:

.featured-image-blog{
height: 220px;
width: 600px;
overflow: hidden;
}
.featured-image-blog img{
height: auto;
width: 600px;
}

和 HTML:

<div class="featured-image-blog">
<?php the_post_thumbnail('featured-image'); ?>
</div>

提前致谢!

最佳答案

由于垂直对齐一直是遗留 HTML 和内容中的一个难题,我建议您给 div:

position: relative;

并给出 img:

position: absolute;
top: 50%;
transform: translate(0, -50%);
-webkit-transform: translate(0, -50%);
-moz-transform: translate(0, -50%);
-ms-transform: translate(0, -50%);

应该可以了..

关于html - 溢出 :hidden div 内的垂直对齐图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22167896/

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