search
HomeWeb Front-endHTML TutorialDocument flow float clear and layout in css_html/css_WEB-ITnose

Document flow

Let’s first talk about what a document flow is. What a flow is is a series of continuous things

 <div style="background-color:pink;width:40px;height:80px;">第一个框 </div>  <div style="background-color:red;width:40px;height:80px;">第二个框 </div>  <div style="background-color:yellow;width:40px;height:80px;">第三个框 </div>  <span>我换行</span>  <span>我不换行</span>


The element system we write in html will be read sequentially in the data stream and placed on the page in order from left to right, top to bottom

Of course during the placement process It involves the concepts of inline elements and block-level elements

A brief explanation

Block-level elements: such as div. Each div element occupies one line. If the width is not set, the entire line will be filled by default. If specified Even if the width is smaller, the following elements must be placed on a new line

Inline elements: span will not wrap. For example, if A is an inline element, the elements following it will be placed to the right of A instead of below

Floating

After talking about document flow, let’s talk about floating

In the above example, the three divs are block-level elements, each occupying one line. But the problem is I just want their layout to be as follows

Look at the code first

  <div style="background-color:pink;width:40px;height:80px;float:left;"></div>  <div style="background-color:red;width:80px;height:80px;"></div>  <div style="background-color:yellow;width:40px;height:80px;">	</div>  <span>我换行</span>  <span>我不换行</span>

You see, there is an extra float: left in the first line of code

What it means is to let this element escape the constraints of the document flow and "float" it to the leftmost side of the container that wraps it (at this time it no longer exists in the document flow)

Looking now The width parameters of those three divs. The width of the dark red is 80. We only see the 40 pixels on the right. The 40 pixels on the left are blocked by the pink div outside the document flow.


The code for this picture is as follows

	<div style="float:left;background-color:pink">			<span>dd</span>			<select name="general.language">					<option value="volo">Volvo</option>					<option value="saab">Saab</option>					<option value="fiat">Fiat</option>					<option value="audi">Audi</option>			</select>	</div>	<div style="background-color:blue">LLL </div>	<div style="background-color:green">  asdf</div>	<div style="background-color:yellow;">	ddddd</div>	<div>	eeee	</div>

If you are using Chrome browser to open the inspection element, you will see


It is actually blue 111div is placed from the top row. The pink div is placed on top of it to block part of it

(lll asdf. The same piece of code is printed in the center. The display is different in editplus and chrome. It should be due to different explanation mechanisms. )

This is also in line with the theory of document flow we talked about above: any element with a float attribute will be taken out of the document flow, and the elements inside the document flow will be placed where they should be

But the problem is, can’t I also write the top line of asdf?

This involves the detailed layout method of float. Let me tell you one sentence

If a div element A is floating. If the previous element of the A element is also floating, then the A element will follow the previous element (if these two elements cannot be placed on one line, then the A element will be squeezed to the next line); if the A element If the previous element is an element in the standard flow, then the relative vertical position of A will not change, that is to say, the top of A will always be aligned with the bottom of the previous element.

The order of divs is determined by the order of divs in the HTML code.

The end close to the edge of the page is the front, and the end far away from the edge of the page is the back.

Then there is another question. What if a itself is not floating? This is a bit of a puzzle. If a is not floating, then it is still in the document flow! This is the description of the big red block in the picture below. The truth


If you still don’t understand, type a few lines of code yourself and see the effect


Analyze that the front element of our page LLL has a floating label, so place the LLL to the right of the front element

The previous element of asdf is LLL, so asdf is placed directly below the LLL, which is the effect in our picture


What should I do?

clear

clear : none | left | right | both
Value:
none : Default value. Floating objects are allowed on both sides
left : Floating objects are not allowed on the left
right : Floating objects are not allowed on the right
both : Floating objects are not allowed

clear itself It is to clear the floating effect of the element itself

We add clear:left to asdf and it will be ok



(The article below is far better than mine and my information basically comes from here. You must read it)

http://www.cnblogs.com/iyangyuan/archive /2013/03/27/2983813.html#undefined


Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
HTML: Building the Structure of Web PagesHTML: Building the Structure of Web PagesApr 14, 2025 am 12:14 AM

HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.

From Text to Websites: The Power of HTMLFrom Text to Websites: The Power of HTMLApr 13, 2025 am 12:07 AM

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.

Understanding HTML, CSS, and JavaScript: A Beginner's GuideUnderstanding HTML, CSS, and JavaScript: A Beginner's GuideApr 12, 2025 am 12:02 AM

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

The Role of HTML: Structuring Web ContentThe Role of HTML: Structuring Web ContentApr 11, 2025 am 12:12 AM

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.

HTML and Code: A Closer Look at the TerminologyHTML and Code: A Closer Look at the TerminologyApr 10, 2025 am 09:28 AM

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

HTML, CSS, and JavaScript: Essential Tools for Web DevelopersHTML, CSS, and JavaScript: Essential Tools for Web DevelopersApr 09, 2025 am 12:12 AM

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.

The Roles of HTML, CSS, and JavaScript: Core ResponsibilitiesThe Roles of HTML, CSS, and JavaScript: Core ResponsibilitiesApr 08, 2025 pm 07:05 PM

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.

Is HTML easy to learn for beginners?Is HTML easy to learn for beginners?Apr 07, 2025 am 12:11 AM

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.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software