html - 将不同尺寸的图像居中放置?

标签 html css image

我有多个包含不同图像的图像,我需要在概览网格中显示这些图像。这些图像确实具有完全不同的尺寸和比例,并且这些图像的包装始终具有相同的高度和宽度。

我想将图像始终放置在 wrapper 的中心,但这行不通。

我用它来做图片

.content_page .slide_content .product img {
    /* max-height: 100%; */
    height: auto;
    width: 100%;
    margin: auto;
    float: none;
    border: none;
}

还有那个 wrapper

.content_page .slide_content .product {
    width: 27%;
    float: none;
    display: inline-block;
    margin: 30px 3%;
    position: relative;
    height: 400px;
    overflow: hidden;
    border-top: 1px solid #121224;
}

非常小或宽的图像现在确实会在包装器的顶部对齐,因为 margin:auto 似乎不起作用。我可以在那里做什么?

最佳答案

.content_page .slide_content .product {
    width:<some width>;
    height:<some width>;
    position:relative;
}

.content_page .slide_content .product > img {
    max-width:100%;
    max-height:100%;
    position:absolute;
    left:0; right:0; top:0; bottom:0;
    margin:auto;
}

关于html - 将不同尺寸的图像居中放置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45185714/

相关文章:

html - 无法使用 Moongose-Pagination-v2 插件在数据表中进行搜索

javascript - 将响应式自定义类添加到移动菜单

jquery:进度条从页面中心增长

html - 单击整个标题 div 时如何使 Bootstrap v4 Accordion 折叠?

javascript - onclick() 和 .on ('click' ,function()) 之间的区别?

php - 在页面上显示 php 生成的图像

css - 我的背景图像未正确缩放。我已经将高度更改为 100%,等等

image - Sitecore 8 RTE 图像大小调整

javascript - 附加到 D3 中时元素不出现

javascript - 突出显示当前菜单项?