1 <html> 2 <head> 3 <style type="text/css"> 4 .main{ 5 height:500px; 6 background-color:red; 7 } 8 .content{ 9 margin:30px; 10 height:300px; 11 background-color:green; 12 } 13 </style> 14 </head> 15 <body> 16 <div class="main"> 17 <div class="content"></div> 18 </div> 19 </body> 20 </html>
当一个元素包含于另外一个元素中时(假设没有padding或border把margin分隔开),他们的上/下margin会发生合并
<style type="text/css"> .main{ height:500px; background-color:red; overflow: hidden; } .content{ margin:30px; height:300px; background-color:green; } </style>
页面就正常了,是我想要的了css
当一个html元素知足下面条件中的任何一点时,均可以产生BFChtml
<html> <head> <style type="text/css"> .main{ float:left; background-color:red; width: 200px; height:100px; } .content{ background-color:green; height:200px; } </style> </head> <body> <div class="main"></div> <div class="content"></div> </body> </html>
页面:布局
<style type="text/css"> .main{ float:left; background-color:red; width: 200px; height:100px; } .content{ overflow:hidden; background-color:green; height:200px; } </style>
页面就变成这样了spa
perfect!!!3d
<html> <head> <style type="text/css"> .main{ border: 5px solid green; width: 300px; } .child{ float:left; width:100px; height:100px; border: 5px solid #f66; } </style> </head> <body> <div class="main"> <div class="child"></div> <div class="child"></div> </div> </body> </html>
页面:code
<style type="text/css"> .main{ overflow:hidden; border: 5px solid green; width: 300px; } .child{ float:left; width:100px; height:100px; border: 5px solid #f66; } </style>
页面orm
小子可能理解的不全,可能理解的有误差,但愿各位前辈多多指教htm