这有一个小例子:
样式:
结构:
1111111
1111111
1111111
1111111
2222222
2222222
2222222
2222222
3333333
3333333
3333333
3333333
结果是这样的:
我的疑问有:
1、浮动是不是使div1彻底脱离了文档流,在文档流里有没有占据位置?
2、为什么div1和div2重合之后,把div2里的文字挤到了边上去?就是说div1与div2重合了,为什么不能与div2里的段落重合?
请求高手详解!!!
回复讨论(解决方案)
绝对定位 才会脱离文档流
楼主 可以去google看看 float和 display clear
float是浮动 没有脱离文档流
一堆有次序的东西 其中有一个是 float
那么你可以想象 他像铁块碰见磁铁一样飞向边缘 空间还是占着(默认的width属性变成auto了)
你说的这两个问题,看W3C中,关于float的解释多直白的,下面两句就是W3C中关于float的叙述:
浮动的框可以向左或向右移动,直到它的外边缘碰到包含框或另一个浮动框的边框为止。
由于浮动框不在文档的普通流中,所以文档的普通流中的块框表现得就像浮动框不存在一样。
详细内容,直接点击查看: http://www.w3school.com.cn/css/css_positioning_floating.asp
还有你说的文字为啥会出现这个情况,也有说明。
你说的这两个问题,看W3C中,关于float的解释多直白的,下面两句就是W3C中关于float的叙述:
浮动的框可以向左或向右移动,直到它的外边缘碰到包含框或另一个浮动框的边框为止。
由于浮动框不在文档的普通流中,所以文档的普通流中的块框表现得就像浮动框不存在一样。
详细内容,直接点击查看: http://www.w3school.com.cn/css/css_positioning_floating.asp
还有你说的文字为啥会出现这个情况,也有说明。
“由于浮动框不在文档的普通流中,所以文档的普通流中的块框表现得就像浮动框不存在一样。”这句话有点儿糊涂,求详细的解释
<html><head><title></title><meta content="text/html; charset=GB2312" /><style>.a{border:1px solid red;width:960px;margin:0 auto;}.b{float:left;height:100px;width:100px;background-color:#aaa}.c{height:50px;background-color:#ddd;}</style></head><body><div class = "a"> <div class = "b"></div> <div class = "c"></div></div></body></html>
效果图:
就拿这段代码说吧,我用a,b,c表示这三个div。
a和c是普通流,b是浮动框。
1:按理论来说,a的高度是以它子元素的总的高度计算的,但是在图中可以看出,a的高度只是和c的高度相同,就是它忽略了b的高度。
2:块框之间,都是上下排列的,每一个块框都占据单独的一行,可以这里,c就当没有看到b存在一样。
这不就是再说,普通流的布局是不考虑是不是在它之前,有浮动框的?
这样说,不知你能清楚我的意思不。
为什么文字会避开,就如同你上面给的代码,这个应该是浏览器本身有对文字进行处理吧,你可以用浏览器调试工具看下,文字的标签
元素,其实还是占据一整行的,只是文字并没有从最左边开始。文字表现这块,是个特例。
<html><head><title></title><meta content="text/html; charset=GB2312" /><style>.a{border:1px solid red;width:960px;margin:0 auto;}.b{float:left;height:100px;width:100px;background-color:#aaa}.c{height:50px;background-color:#ddd;}</style></head><body><div class = "a"> <div class = "b"></div> <div class = "c"></div></div></body></html>
效果图:
就拿这段代码说吧,我用a,b,c表示这三个div。
a和c是普通流,b是浮动框。
1:按理论来说,a的高度是以它子元素的总的高度计算的,但是在图中可以看出,a的高度只是和c的高度相同,就是它忽略了b的高度。
2:块框之间,都是上下排列的,每一个块框都占据单独的一行,可以这里,c就当没有看到b存在一样。
这不就是再说,普通流的布局是不考虑是不是在它之前,有浮动框的?
这样说,不知你能清楚我的意思不。
为什么文字会避开,就如同你上面给的代码,这个应该是浏览器本身有对文字进行处理吧,你可以用浏览器调试工具看下,文字的标签
元素,其实还是占据一整行的,只是文字并没有从最左边开始。文字表现这块,是个特例。
谢谢你的耐心解答,我说的我都知道,但是就是文字表现这块儿不懂,大家都说是特例,但我想明白这是怎么回事,在元素浮动的时候,普通文档流是怎么变化的。如果你能回答就太好了!不管怎样,这分就给你了!
这个,我也不知道咋回事,应该是浏览器规定的吧,不过没有看到过相关的文章。
所以,还真是回答不了。
这个问题我也纳闷 貌似这篇文章http://blog.sina.com.cn/s/blog_5f90da9b01016cmo.html有讲到但是我看不懂

HTML is a language used to build web pages, defining web page structure and content through tags and attributes. 1) HTML organizes document structure through tags, such as,. 2) The browser parses HTML to build the DOM and renders the web page. 3) New features of HTML5, such as, enhance multimedia functions. 4) Common errors include unclosed labels and unquoted attribute values. 5) Optimization suggestions include using semantic tags and reducing file size.

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

The role of HTML is to define the structure and content of a web page through tags and attributes. 1. HTML organizes content through tags such as , making it easy to read and understand. 2. Use semantic tags such as, etc. to enhance accessibility and SEO. 3. Optimizing HTML code can improve web page loading speed and user experience.

HTMLisaspecifictypeofcodefocusedonstructuringwebcontent,while"code"broadlyincludeslanguageslikeJavaScriptandPythonforfunctionality.1)HTMLdefineswebpagestructureusingtags.2)"Code"encompassesawiderrangeoflanguagesforlogicandinteract

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.

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.

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.

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver CS6
Visual web development tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),