BFC的个人理解以及解决什么样的问题

BFC : 页面上的一个隔离的独立渲染区域(常用于解决边距重叠 高度坍陷 margin塌陷 文本环绕)

区域里面的子元素不会影响到外面的元素 外面的元素也不会影响到区域里面的子元素
             float:left right
             Position absolute fixed
             display inline-block table-cell
             overflow:hidden auto scroll
  1. 解决边距重叠
	<style>
	/**
	增加BFC属性*/
	.box{
	overflow:hidden;
}
		/**这个时候回出现边距重叠问题*/
       .box1{
            width: 100px;
            height: 100px;
            margin-bottom: 100px;
        }
        .box .box2{
            width: 100px;
            height: 100px;
            margin-top:100px
        }

</style>
    <div class="box1"></div>
    <div class="box2"></div>


<!--Bfc解决-->
	<div class="box">
	 <div class="box1"></div></div>
	<div class="box">
	    <div class="box2"></div>
</div>
  1. 高度塌陷
<style>
   .box{
            width: 200px;
            border: 10px solid #000;
            /**增加bFC属性*/
            overflow: hidden;
        }
        .box1{
            float: left;
            width: 100px;
            height: 100px;
            background-color: green;
        }
        .box2{
            float: left;
            width: 100px;
            height: 100px;
            background-color: red;
        }

</style>
<div class="box">
    <div class="box1"></div>
    <div class="box2"></div>
</div>
  1. margin塌陷
<style>
        .box1{
            /*不用bfc解决margin塌陷*/
            border-top: 1px solid transparent;
            width: 300px;
            height: 300px;
            background-color: #000;
        }

        .box2{
            width: 50px;
            height: 50px;
            margin: 0 auto;
            margin-top: 100px;
            background-color: orange;

        }
</style>

<div class="box1">
    <div class="box2"></div>
</div>
  1. 文本环绕 (同理添加BFC属性)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值