如何正确清除这些浮动的div?

时间:2015-08-14 15:41:02

标签: html css clearfix

我认为我理解使用CSS进行clearfixing的:after方法 - 但我似乎无法让它正常工作。出于某种原因,siblingContainer包含浮动元素之后的buttonContainer似乎没有清除?

HTML:

<div class="buttonContainer">
    <div class="action_button">Button 1</div>
    <div class="action_button">Button 2</div>
</div>
<div class="siblingContainer"></div>

CSS:

.action_button {
    font-family: Arial;
    font-size: 9pt;
    font-weight: bold;
    background-color: #f2c059;
    color: white;
    border-radius: 5px;
    display: inline-block;
    padding: 5px;
    cursor: pointer;
}
.buttonContainer {
    margin: 5px;
}
.buttonContainer div {
    margin: 0 5px;
    float: right;
}
.buttonContainer div:last-child:after {
    content: "";
    display: block;
    clear: both;
}
.siblingContainer {
    height: 500px;
    background: gray;
}

小提琴: http://jsfiddle.net/np0c6feh/1/

0 个答案:

没有答案