html - 在顶部对齐不同高度的div

标签 html css

这是我的 HTML 标记:

<div class="awards-wrap">
    <div class="award">
        <img src="http://placehold.it/200x200">
        <p>Lorem ipsum dolor sit amet</p>
        <p>Lorem ipsum dolor</p>
        <p>Lorem ipsum 2013</p>
    </div>
    <div class="award">
        <img src="http://placehold.it/200x200">
        <p>Lorem ipsum dolor sit amet</p>
    </div>
    <div class="award">
        <img src="http://placehold.it/200x200">
        <p>Lorem ipsum dolor sit amet</p>
        <p>Lorem ipsum dolor sit amet</p>
        <p>Lorem ipsum dolor</p>
        <p>Lorem ipsum 2013</p>
    </div>
</div>

这是我的CSS:

.awards-wrap {
    background: gray;
    margin: 0 auto;
    text-align: center;
}

.award {
    max-width: 250px;
    display: inline-block;
}

所以它们现在都居中对齐并且也是响应式的,但我希望图像都在顶部对齐。

我试过这样做:

.awards-wrap {
    background: gray;
    margin: 0 auto;
    text-align: center;
    display: table;
}

.award {
    max-width: 250px;
    display: table-cell;
}

但它消除了响应能力并在中心对齐。我知道我可以对它使用媒体查询,但我只想像它在 inline-block 上的行为那样做。

这是 jsfiddle为之

最佳答案

您可以为此使用vertical-align 属性并将其设置为top。它也会将 div 对齐到顶部和中心。这是更新后的 CSS:

.award {
 max-width: 250px;
 display: inline-block;
 vertical-align:top;
}

这是一个link更新后的 JSFiddle

关于html - 在顶部对齐不同高度的div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34195780/

相关文章:

javascript - 使用背景附件 :fixed 时图像在 chrome 中移动

javascript - 动态重新排列 child 以适应有限空间中的大多数

html - 使用 AngularJS 的动态工具提示

javascript - 如何更新多个 HTML 页面中的静态内容

javascript - 我可以控制有多少选项使选择标签变得可滚动吗?

html - css - 仅着色边框

html - 如何将 DIV 标记定位为悬停(z-index)在表格单元格上

html - 使重叠 div 中的按钮可点击

javascript - 区分 docusaurus 中的页面/内容

css - IE 忽略样式表中的@media