CSS Basics Tutorial: Clear Floats
CSS has two functions for clearing floats:
(1) You can surround elements to "visually" wrap floating elements
(2) Other elements under clearing will return to the default layout.
Note:
If there is floating, there must be clearing.
If the surrounding element has a specified height, then the clearing function does not need to be used.
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>php.cn</title> <style type="text/css"> img{ width:200px; float:left; } .clear{clear:left;} </style> </head> <body> <h1>習(xí)近平心中的互聯(lián)網(wǎng)</h1> <p>互聯(lián)網(wǎng)是20世紀(jì)最偉大的發(fā)明,它正在將人類“一網(wǎng)打盡”,人們在不知不覺中已經(jīng)融入了互聯(lián)網(wǎng)生態(tài),互聯(lián)網(wǎng)讓世界變成了“雞犬之聲相聞”的地球村。</p> <img src="http://img.kanzhun.com/upload/image/20150616/ccd02d7d2bcf7451de277579c453ccde.jpg" > <div class="clear"></div> <p>互聯(lián)網(wǎng)是20世紀(jì)最偉大的發(fā)明,它正在將人類“一網(wǎng)打盡”,人們在不知不覺中已經(jīng)融入了互聯(lián)網(wǎng)生態(tài),互聯(lián)網(wǎng)讓世界變成了“雞犬之聲相聞”的地球村。</p> </body> </html>
Note: You can try to delete the statement that clears floats and see if there are any changes in the output