What are the css layout methods?
css layout methods include: 1. Static layout (Float layout and absolute layout); 2. Adaptive layout; 3. Fluid layout (left fixed, right adaptive, left and right fixed width, middle adaptive, Holy Grail layout, double flying wing layout); 4. Responsive layout; 5. Flexible layout.
The operating environment of this tutorial: Windows7 system, CSS3&&HTML5 version, Dell G3 computer.
We have developed from css to the current major categories that can be summarized into the following categories. The implementation methods you know may be the specific implementations in the following ways:
- Static layout
- Adaptive layout
- Flowing layout (also known as percentage layout%)
- Responsive layout: media query
- Flexible layout (rem/em flex layout)
1. Static layout
The most traditional layout method, all sizes in the web page are in px as the unit, and min-width is set. If the width is less than this width, a scroll bar will appear. If it is greater than this width, the content will be centered and the background will be added. .
Implementation method:
PC: Centered layout, all styles use absolute width/height (px), design a Layout, when the screen width and height are adjusted, use Horizontal and vertical scroll bars to view the obscured parts;
Mobile devices: In addition, create a mobile website, design a separate layout, and use different domain names such as wap. or m.
Advantages: Using the previous CSS2 layout method, the layout is simple and there are no compatibility issues.
Disadvantages: It cannot be displayed reasonably on the mobile phone, and the PC page cannot be used on the mobile phone, so another layout needs to be written to present it.
Practice case:
- Float layout
- Absolute layout
2. Adaptive layout
can be seen as consisting of multiple static layouts under different screens. Adaptive layout defines different layouts for different screen resolutions. Changing the screen resolution can switch between different static layouts (the position of page elements may change), but in each static layout, the page elements do not change as the window size is adjusted. Adaptive layoutThe position of the elements in the page will change, which is a good solution to the disadvantage of low utilization of large screen space in the fluid layout.
When the screen resolution changes, the position of the elements on the page will change but the size will not.
Practical case: Baidu search homepage
(Learning video sharing: css video tutorial)
3. Flow layout
The size of the main divided areas in the web page uses percentage (used with the min-* and max-* attributes) to set the layout format for different screens. When the screen size changes, Different layouts will appear, which means that on this screen, the element block will be in this place, but on that screen, the element block will appear in that place. Only the layout changes, the elements remain unchanged. It can be seen as consisting of multiple static layouts under different screens.
The characteristic of fluid layout is that as the screen changes, the layout of the page does not change significantly and can be adapted and adjusted. This just complements the adaptive layout. Use % percentage to define the width, and the height is mostly fixed in px. It can be adjusted according to the real-time size of the visual area (viewport) and the parent element to adapt to various resolutions as much as possible. Properties such as max-width/min-width are often used to control the size flow range to avoid being too large or too small and affecting reading. This layout method was used in the early history of Web front-end development to cope with PC screens of different sizes (the difference in screen size at that time was not too big), is also used in today's mobile development Commonly used layout methods, buthas obvious shortcomings:The main problem is that if the screen size span is too large, then on a screen that is too small or too large relative to its original design Cannot be displayed normally. Because the width is defined using %, but the height and text size are mostly fixed in px, the display effect on a large-screen mobile phone will become that the width of some page elements is stretched very long, but the height and text size are still the same as the original ones. The same (that is, these things cannot become "flowing"
When the screen resolution changes, the size of the elements on the page will change but the layout will not change.
Main practice cases:
The left side is fixed and the right side is adaptive
The left and right fixed widths are adaptive in the middle
Holy Grail Layout
Double flying wing layout
4. Responsive layout
Responsive design can make the website have a better browsing and reading experience on mobile phones and tablets. Different screen sizes will result in different web page content being displayed to users. Using Media Query can detect the size of the screen (mainly detecting width), and set different CSS styles to achieve responsive layout. Mainly relies on css media queries.
There will be a layout style under each screen resolution, that is, the position and size of elements will change.
Practical case media query
5. Flexible layout
- ##rem/em
- flex layout
Programming Video! !
The above is the detailed content of What are the css layout methods?. For more information, please follow other related articles on the PHP Chinese website!

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

React combines JSX and HTML to improve user experience. 1) JSX embeds HTML to make development more intuitive. 2) The virtual DOM mechanism optimizes performance and reduces DOM operations. 3) Component-based management UI to improve maintainability. 4) State management and event processing enhance interactivity.

React is the preferred tool for building interactive front-end experiences. 1) React simplifies UI development through componentization and virtual DOM. 2) Components are divided into function components and class components. Function components are simpler and class components provide more life cycle methods. 3) The working principle of React relies on virtual DOM and reconciliation algorithm to improve performance. 4) State management uses useState or this.state, and life cycle methods such as componentDidMount are used for specific logic. 5) Basic usage includes creating components and managing state, and advanced usage involves custom hooks and performance optimization. 6) Common errors include improper status updates and performance issues, debugging skills include using ReactDevTools and Excellent

React components can be defined by functions or classes, encapsulating UI logic and accepting input data through props. 1) Define components: Use functions or classes to return React elements. 2) Rendering component: React calls render method or executes function component. 3) Multiplexing components: pass data through props to build a complex UI. The lifecycle approach of components allows logic to be executed at different stages, improving development efficiency and code maintainability.

TypeScript enhances React development by providing type safety, improving code quality, and offering better IDE support, thus reducing errors and improving maintainability.

The article explains using useReducer for complex state management in React, detailing its benefits over useState and how to integrate it with useEffect for side effects.

React is a JavaScript library for building user interfaces, with its core components and state management. 1) Simplify UI development through componentization and state management. 2) The working principle includes reconciliation and rendering, and optimization can be implemented through React.memo and useMemo. 3) The basic usage is to create and render components, and the advanced usage includes using Hooks and ContextAPI. 4) Common errors such as improper status update, you can use ReactDevTools to debug. 5) Performance optimization includes using React.memo, virtualization lists and CodeSplitting, and keeping code readable and maintainable is best practice.

The React ecosystem includes state management libraries (such as Redux), routing libraries (such as ReactRouter), UI component libraries (such as Material-UI), testing tools (such as Jest), and building tools (such as Webpack). These tools work together to help developers develop and maintain applications efficiently, improve code quality and development efficiency.

React is a front-end framework for building user interfaces; a back-end framework is used to build server-side applications. React provides componentized and efficient UI updates, and the backend framework provides a complete backend service solution. When choosing a technology stack, project requirements, team skills, and scalability should be considered.
