深入理解CSS盒模型与BFC作用

<!DOCTYPE html>
<html>
<head>
	<title>css盒模型</title>
	<style type="text/css">
		html *{
			margin: 0;
			padding: 0;
		}
	</style>
</head>
<body>

	<!-- BFC垂直方向边距重叠 -->
    <section id="margin">
      	<style>
      	  #margin{
      	    background: pink;
      	    overflow: hidden;
      	  }
      	  #margin p{
      	    color: #f55;
        	background: #fcc;
        	width: 100px;
        	line-height: 50px;
        	text-align:center;
        	margin: 50px;
      	  }
      	</style>
      	<p>1</p>
      	<p>2</p>
      	<div style="overflow: hidden;">
        	<p>3</p>
    	</div>     	
    </section>

	<!-- BFC不与float重叠 -->
	<section id="layout">
        <style media="screen">
          #layout{
          	margin-top: 50px;
            background: red;
          }
          #layout .left{
            float: left;
            width: 100px;
            height: 100px;
            background: yellow;
          }
          #layout .right{
          	width: 500px;
            height: 130px;
            background: green;
            overflow: hidden;
          }
        </style>
        <div class="left"></div>
        <div class="right"></div>
      </section>

      <!-- BFC子元素即使是float也会参与计算 -->
      <section id="float">
        <style media="screen">
          #float{
          	margin-top: 50px;
            background: red;
            overflow: hidden;
          }
          #float .float{
            float: left;
            font-size: 30px;
          }
        </style>
        <div class="float">我是浮动元素</div>
      </section>


	  <!-- 利用BFC清除内部浮动 -->
      <section class="par">
      	<style type="text/css">
      		.par {
      			margin-top: 50px;
        		border: 5px solid #fcc;
        		width: 300px;

        		/*利用BFC清除内部浮动*/
        		overflow: hidden;
    		}
    		.child {
    		    border: 5px solid #f66;
    		    width:100px;
    		    height: 100px;
    		    float: left;    		    
    		}
      	</style>
      	<div class="child"></div>
        <div class="child"></div>
      </section>

</body>
</html>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值