css常用知识点

2020-04-22  本文已影响0人  RiverSouthMan

清除浮动的方法有哪些?

第一种:clear:both

在父元素的里面添加一个空的clear的div(跟浮动的子级同级),然后再为这个类添加属性值clear:both;便可以清除浮动。

第二种:overflow:hidden

在父元素的样式中添加overflow: hidden;也可以清除浮动,如下css代码,但不提倡使用这个方法,overflow: hidden;还有一个意思就是隐藏超出的部分,处理不好还是会给页面带来麻烦。

第三种:clearfix(推荐使用)

1.在父集元素类名中添加 clear-fix
2.写伪类样式

<style>  
.clear-fix::after {
   content:""; 
   display: block; 
   clear:both; 
}
</style>

<div class="header-line clear-fix">
            <div class="header-logo">
                <a class="logo"href=" https://www.meisaas.com/index.html">样式方案</a>
            </div>
</div>
上一篇 下一篇

猜你喜欢

热点阅读