Pin element to the bottom of the container

不羁的心 提交于 2019-12-14 03:58:43

问题


Looking for the View Button to be locked to the bottom, using position:absolute; would cause the price to merge into the View Button.

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;
}

Any questions please ask.


回答1:


You need to make your div.offer box a (nested) flex container in column-direction. Then pin the view button to the bottom with a flex auto margin.

.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

A few more things to keep in mind:

  • Flex layout exists only between parent and child.

  • Floats are ignored in a flex container.

  • Avoid using percentages for margin and padding in a flex container.



来源:https://stackoverflow.com/questions/42137339/pin-element-to-the-bottom-of-the-container

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!