天天看點

css之如何清除浮動

一共有四種方式,參考連結:https://www.cnblogs.com/wush-1215/p/10623243.html

我個人更喜歡雙僞類方式:

<style type="text/css">
    li {
        list-style: none;
        height: 100px;
        width: 100px;
        float: left;
        background: red;
        margin-left: 20px;
    }
    
    .father:after,
    .father:before {
        content: "";
        display: block;
        clear: both;
    }
    
    ul {
        background: pink;
    }
</style>
<ul class="father">
    <li></li>
    <li></li>
</ul>