Clear float common method

1. After the last float label, add a new label, its style to the Clear: both-;
2. Add the parent element style overflow: hidden; this method will cut off the extra content can not be displayed overflow elements
3. using double dummy elements before and after the floating Clear

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>image</title>
    <style>
        * {padding: 0;margin: 0;}
        p{float: left;}
        .clearfix::before,.clearfix::after {
            content: ".";
            display: block;
            height: 0;
            line-height: 0;
            visibility: hidden;
            clear: both;
        }
    </style>
</head>

<body>    
    <div style="border:1px solid green;" class="clearfix">
        <p style="width:100px;height:100px;background:red;"></p>
        <p style="width:100px;height:100px;background:red;"></p>
        <p style="width:100px;height:100px;background:red;"></p>
    </div>
    
</body>
</html>
Published 77 original articles · won praise 7 · views 9096

Guess you like

Origin blog.csdn.net/Misnice/article/details/104070448