search
HomeWeb Front-endHTML TutorialCSS layout layout model

This time I will bring you the layout model of CSS layout. What are the precautions of CSS layout model? Here is a practical case, let’s take a look.

In web pages, elements have three layout models:
1. Flow model (Flow) Default
2. Float model (Float)
3. Layer model (Layer)

1. Flow model (Flow)

The flow (Flow) model is the default web page layout mode. That is to say, the HTML web elements of the web page in the default state distribute the web page content according to the flow model.

The fluid layout model has two typical characteristics:

First, the block elements will be vertically extended and distributed in order from top to bottom within the containing element, because in By default, the width of block elements is 100%. In fact, block elements all occupy positions in the form of rows.

(Each sticky note displays its original default width and height)

Second point, under the flow model, inline elements will move from left to right within the containing element. Horizontal distribution display. (Inline elements are not as dominant as block elements occupying a line)

2. Floating model (Float)

Any element cannot float by default. But it can be defined as floating using CSS

div{float:left;} div{float:right;}

You can set different floating methods for different divs to layout.

3. Layer model (Layer)

The layer model has three forms:

1. Relative positioning (position: relative)

2, Absolute positioning(position: absolute)

3. Fixed positioning(position: fixed)

Relative positioning

If you want to To set relative positioning in the layer model, you need to set position:relative (indicating relative positioning), which determines the offset position of the element in the normal document flow through the left, right, top, and bottom attributes.

Move relative to the previous position, and the position before the offset remains unchanged. When using relative positioning, even if the element is offset, it still occupies the space before it was offset.

Absolute positioning

If you want to set the absolute positioning in the layer model for an element, you need to set position:absolute (indicating absolute positioning), drag the element out of the document flow, and then use left, The right, top, and bottom attributes are absolutely positioned relative to their closest parent containing block with a positioning attribute. If there is no such containing block (that is, the div in front of it does not have a positioning attribute set), it will be relative to the body element, that is, relative to the browser window.

Elements that are set to absolute positioning do not occupy space in the document flow. If an element is set to absolute positioning, its position in the document flow will be deleted;

We can set their stacking order through z-index.

Absolute positioning makes the element out of the document flow, so it does not occupy space. The layout of the element in the ordinary document flow is the same as when the absolutely positioned element does not exist. Other elements still in the document flow will ignore the element and Fill his former space. Because absolutely positioned boxes are independent of document flow, they can cover other elements on the page.​

The positioning of the floating element is still based on the normal document flow, and then extracted from the document flow and moved as far as possible to the left or right side, and the text content will surround the floating element. It only changes the display of the document flow, but does not break away from the document flow. Understanding this, it is easy to figure out when to use positioning and when to use floating.

Fixed positioning

fixed: Indicates fixed positioning, similar to the absolute positioning type, but its relative movement coordinates are the view (web page window within the screen) itself. Since the view itself is fixed, it will not change as the scroll bar of the browser window scrolls, unless you move the screen position of the browser window on the screen, or change the display size of the browser window, so fixedly positioned elements will always be in A position within the view within the browser window that is not affected by the flow of the document.

#div1{
position:fixed;
    bottom:0;
    right:0
}  (始终在屏幕由下端有一个div框,会一直跟着滚动条走)

Relative positioning can be mixed with absolute positioning. The principle is: as long as the parent div defines the positioning attribute, the child div will be repositioned according to the position of the parent div.

I believe after reading these cases You have mastered the method. For more exciting information, please pay attention to other related articles on the php Chinese website!

Related reading:

How to solve the problem of abnormal display after layer.photos() asynchronously modifies the image address

How Monitor whether the angularJs list data has been rendered

The relationship between ES6 "classes" and object-oriented

The above is the detailed content of CSS layout layout model. For more information, please follow other related articles on the PHP Chinese website!

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 as a Markup Language: Its Function and PurposeHTML as a Markup Language: Its Function and PurposeApr 22, 2025 am 12:02 AM

The function of HTML is to define the structure and content of a web page, and its purpose is to provide a standardized way to display information. 1) HTML organizes various parts of the web page through tags and attributes, such as titles and paragraphs. 2) It supports the separation of content and performance and improves maintenance efficiency. 3) HTML is extensible, allowing custom tags to enhance SEO.

The Future of HTML, CSS, and JavaScript: Web Development TrendsThe Future of HTML, CSS, and JavaScript: Web Development TrendsApr 19, 2025 am 12:02 AM

The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

HTML: The Structure, CSS: The Style, JavaScript: The BehaviorHTML: The Structure, CSS: The Style, JavaScript: The BehaviorApr 18, 2025 am 12:09 AM

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

The Future of HTML: Evolution and Trends in Web DesignThe Future of HTML: Evolution and Trends in Web DesignApr 17, 2025 am 12:12 AM

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

HTML vs. CSS vs. JavaScript: A Comparative OverviewHTML vs. CSS vs. JavaScript: A Comparative OverviewApr 16, 2025 am 12:04 AM

The roles of HTML, CSS and JavaScript in web development are: HTML is responsible for content structure, CSS is responsible for style, and JavaScript is responsible for dynamic behavior. 1. HTML defines the web page structure and content through tags to ensure semantics. 2. CSS controls the web page style through selectors and attributes to make it beautiful and easy to read. 3. JavaScript controls web page behavior through scripts to achieve dynamic and interactive functions.

HTML: Is It a Programming Language or Something Else?HTML: Is It a Programming Language or Something Else?Apr 15, 2025 am 12:13 AM

HTMLisnotaprogramminglanguage;itisamarkuplanguage.1)HTMLstructuresandformatswebcontentusingtags.2)ItworkswithCSSforstylingandJavaScriptforinteractivity,enhancingwebdevelopment.

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.

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

Video Face Swap

Video Face Swap

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

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

mPDF

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),

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.