关于清除浮动的一些简单理解。 - DD狗
在我们学习css时,利用浮动可以为我们的的布局样式提供很大的便利,但是随着而来,我们也会遇到清除浮动的问题,关于清除浮动,我谈一谈我的一些简单看法。
首先,我们为什么要清除浮动,因为浮动会使该标签脱离文档流,对前后的元素,还有父元素(边框,内容)都会造成影响。
下面说一说清除浮动的方法:
1 定义height
为父元素增加一个固定或最少的height,因为当子元素设置为浮动后,脱离了文档流后,会导致父元素的边框无法撑开。所以我们可以增加一个
“height:”或者“min-height:“来解决。
这种方法的优点在于 : 上手容易,简单易懂。
缺点在于 : 要对高度进行详细的确定,且不灵活。
2 利用clear:both
在父元素的结束标签加入clear:both。在父元素内增加一个空白签,来声明其周围忽略浮动。
html中
css中 .clear{
clear:both
}
这种方法的优点在于 简单方便。
缺点在于 编程最忌讳添加很多空标签也会对以后的修改造成麻烦。
3 利用overflow:hidden
为父元素在css中添加 overflow:hidden,我们现在看看他们的意思是什么,overflow:溢出 ,hidden:清除。也就是清除溢出的部分,不显示其内容。那么很容易明白,利用这个,就是将带有浮动属性的
."class名称"{
overflow:hidden
}
这种方法的优点在于:代码使用的少,错误少。
缺点在于:无法与position一起使用,也不能同时定义height,因为是将多余的部分清除掉。
以上三个方法是我在初学css清除浮动时用到学到的方法,作为一个web小白,能力有限,所解决问题的办法可能也不是最好的,欢迎大家提议,谢谢。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics





HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

The Y-axis position adaptive algorithm for web annotation function This article will explore how to implement annotation functions similar to Word documents, especially how to deal with the interval between annotations...

GiteePages static website deployment failed: 404 error troubleshooting and resolution when using Gitee...

To achieve the effect of scattering and enlarging the surrounding images after clicking on the image, many web designs need to achieve an interactive effect: click on a certain image to make the surrounding...

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.
