Created
March 9, 2016 23:17
-
-
Save clinyong/a171b1b78b3b83a744ef to your computer and use it in GitHub Desktop.
清除浮动两种方法的差异
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!doctype html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <title>clear与margin重叠</title> | |
| </head> | |
| <body> | |
| 1. | |
| <div style="background-color: #f5f5f5;"> | |
| <img src="http://img.mukewang.com/53d60af3000171a002560191.jpg" style="float:left;"> | |
| <div style="clear:both; margin-bottom:100px;">clear:both;</div> | |
| </div> | |
| <div style="margin-top: 100px;">本文字离图片的距离是?</div> | |
| <br><br><br><br>2. | |
| <div style="background-color: #f5f5f5; overflow: hidden;"> | |
| <img src="http://img.mukewang.com/53d60af3000171a002560191.jpg" style="float:left; margin-bottom: 100px;"> | |
| </div> | |
| <div style="margin-top: 100px;">本文字离图片的距离是?</div> | |
| </body> | |
| </html> |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
第一种是在浮动元素后面加上
clear:both的元素,这时候的 margin 会与外部产生重叠。第二种是在浮动元素的父元素加上
overflow:hidden,也就是形成 BFC,这样与外部就隔绝了。