Home > Web Front-end > CSS Tutorial > center vertically horizontally

center vertically horizontally

高洛峰
Release: 2016-10-09 13:46:21
Original
1599 people have browsed it

Vertical and horizontal centering


center vertically horizontally

This is the body code

  1. Vertical and horizontal centering

    center vertically horizontally

Analysis: parent element relative child element absolute, child element sets width and height, top and left settings is 50%, margin-top and margin-left are set to half the height and width multiplied by -1.

2. Horizontal centering:

Method 1: margin: 0 auto;

center vertically horizontally

Method 2:

center vertically horizontally

Analysis: parent element relative, child element absolute, child element set width, left: 50%; margin-left: half of the width multiplied by -1;

3. Vertical centering:

center vertically horizontally

Analysis: parent element relative, child element absolute, child element set height, top: 50%; margin-top: half the width multiplied by -1;

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