css - 如何在文章列表中垂直居中图像?

标签 css sass

我的元素的文章/教程列表有问题。

Scenario (图像可以是其他尺寸,而不是 256x256,但必须是正方形,不能使用背景技巧,因为我在服务器上使用 Handlebars ,图像不需要使用 position: absolute)

最佳答案

.tutorial {
    background-color: #ccc;
    position: relative;
    img {
        position: absolute;
        display: inline-block;
        width: 50px;
        height: 50px;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        margin: auto 0;
    }
...

top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto 0;

是什么让它垂直居中。

.tutorial 上的 position: relative; 使 img 垂直居中。否则它会在屏幕上垂直居中。

关于css - 如何在文章列表中垂直居中图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41656404/

相关文章:

html - 如何使文本不重叠它的容器?

node.js - Grunt + Compass 不创建 CSS 文件

css - 由于 CSS 自定义属性而导致 Sass 中断?

css - 如何使用scss @include

html - SVG 多边形指向 CSS 剪辑路径

css - IE svg 缩放问题

html - 为什么当前页面链接在我的代码中没有不同?

html - Box-Shadow 在 IE8 中悬停时不起作用

asp.net - Bootstrap 3.0 "row"第一项未正确对齐

sass - Scss 主题取决于具有预定义变量的主体类