Home > Web Front-end > HTML Tutorial > CSS page layout notes_html/css_WEB-ITnose

CSS page layout notes_html/css_WEB-ITnose

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-24 11:38:28
Original
1085 people have browsed it

Centered layout

Horizontally centered

The width of both the parent element and the child element is unknown

inline-block text-ailgn

.child{display:inline-block;}.parent{text-align:center;}    
Copy after login

Advantages: Good compatibility
Disadvantages: The text of the sub-element inherits the text-align attribute, and the sub-element needs to add text-align: left; Style

absolute transform

.child{display:table; margin:0 auto;}
Copy after login

Advantages: Centering child elements will not affect other elements

Disadvantages: transform is a property of CSS3 and has compatibility issues

flex justify-content
.parent{position:relative;}.child{position:absolute; left:50%; transform: translateX(-50%);
Copy after login


Advantages: Only need to set the style of the parent element

Disadvantages: Compatibility issues

flex margin
.parent{display:flex; justify-content:center;}
Copy after login


Vertical Centered

The height of the parent container and child container is unknown

.parent{display:flex;}.child{margin:0 auto;}
Copy after login
table-cell vertical-align

Advantages: Good compatibility

absolute transform

.parent{display:table-cell; vertical-align:middle;}
Copy after login

Advantages: child elements will not interfere with other elements

Disadvantages: compatibility

flex align-item
.parent{position:relative;}.child{position:absolute; top:50%; transform:translateY(-50%);}
Copy after login


Advantages: only the parent element needs to be set

Disadvantages: Compatibility issues

Horizontal and vertical centering
.parent{display:flex; align-items:center;}
Copy after login

The heights of both parent and child containers are unknown

inline-block text-align table-cell vertical-align

absolute transform

flex justify-content align-item
.parent{text-align:center; display:table-cell; vertical-align:middle;}.child{display: inline-block;}
Copy after login

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template