How to center div with css

青灯夜游
Release: 2023-01-05 16:09:08
Original
6287 people have browsed it

Method: 1. Use the "position:absolute" and "transform:translate(-50%,-50%)" styles in the div to center it. 2. Use the "position:absolute" and "margin:auto" styles in the div to center it.

How to center div with css

The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.

Method 1:

Use absolute positioning of the div: absolute, and set the left and top values ​​to 50%. Use the CSS3 transform attribute. transform: translate(-50%,-50%).

How to center div with css

Rendering:

How to center div with css

##Method 2:

Pair div Use absolute layout position:absolute; and set the values ​​of top, left, right, and bottom to be equal, but not necessarily equal to 0; and set margin:auto.

How to center div with css

Rendering:

How to center div with css

(Learning video sharing:

css video tutorial)

The above is the detailed content of How to center div with css. For more information, please follow other related articles on the PHP Chinese website!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!