css - 在 div 中居中对齐图像

标签 css image firefox alignment center

HTML

<div class="image-container">
   <img class="image" src="image.png">
</div>

CSS

.image-container {
    width: 95px;
    height: 95px;
    background: #000000;

    display: -webkit-flex;
    display: flex;

    -webkit-align-items: center;
    align-items: center;

    -webkit-justify-content: center;       
    justify-content: center;
}

.image {
    max-width: 95px;
    max-height: 95px;
}

这在 Chrome 和 Safari 上工作正常,但在 Firefox 上不行。它填满了整个 div 并且纵横比没有保持。如何在 Firefox 上运行?

Chrome/Safari

enter image description here

火狐

enter image description here

最佳答案

因为您的 .image 高度拉伸(stretch)图像。像这样更改您的 CSS。

.image {
    width:100%;
}

关于css - 在 div 中居中对齐图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27504049/

相关文章:

css - 为 csslint 消息寻找 vim efm

css - 最小高度不能正常工作?

JavaScript:处理事件的有效方法(特定于 Firefox)

html - 为什么我的带有 javascript 的元素会出现在我的 Nav 前面

css - 将 CSS 类添加到 date_select

html - 我怎样才能将我的 flex 元素展开到超过容器的宽度?

php - 使用 Codeigniter 进行图像缓存

image - 处理 statusCode : 403 for Image. 网络

css - 响应式背景图片 - 全屏

javascript - 在 Firefox SDK main.js 中获取某些文件的内容