html - 将元素固定到容器底部

标签 html css flexbox css-position

寻找要锁定在底部的 View 按钮,使用 position:absolute; 会导致价格合并到 View 按钮中。

https://jsfiddle.net/kieranbs96/pj8emf0a/

a.view-button {
 float: left;
 padding: 7px 30px;
 background: #e35f00;
 color: #ffffff;
 text-transform: uppercase;
}

.offer, .recommendation {
 float: left;
 flex: 1 0 32%;
 margin: 0 0.3%;
 width: 32%;
 position: relative;
}

有任何问题请提出。

最佳答案

您需要使您的 div.offer 框成为列方向的(嵌套) flex 容器。然后用 flex auto 边距将 View 按钮固定到底部。

.offer, .recommendation {
    float: left;
    flex: 1 0 32%;
    margin: 0 0.3%;
    width: 32%;
    position: relative;

    display: flex;          /* new */
    flex-direction: column; /* new */
}

a.view-button {
    float: left;
    padding: 7px 30px;
    background: #e35f00;
    color: #ffffff;
    text-transform: uppercase;
    position: relative;
    bottom: 0;
    left: 0;

    margin-top: auto;       /* new */
}

revised fiddle

还有几点需要注意:

关于html - 将元素固定到容器底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42137339/

相关文章:

html - 当我将我的背景大小设置为除了覆盖之外的任何内容时,每当图像调整大小时,我的 div 内的文本就会溢出。我该如何防止呢?

html - 如何将滚动条放置在表格一侧?

javascript - 为什么 ../file 路径在 css 和 html 中不起作用?

javascript - insertRule 不适用于关键帧

html - 我可以在 flexbox 行之间有一条线吗?

html - 对齐 html 输入并提交

html - 居中绝对定位溢出div

html - 检查设备是否可以悬停

css - 将单个元素移动到 flex 容器的末尾

html - Flexbox 拉伸(stretch)和对齐元素(在第二行和不同的屏幕上)