Home >Web Front-end >HTML Tutorial >CSS DIV horizontal centering problem_html/css_WEB-ITnose

CSS DIV horizontal centering problem_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 12:32:591390browse

Many new friends will encounter the problem of horizontal centering, which is summarized as follows:

Method 1:

.center{

margin-left :auto;

margin-right:auto;

}

is equivalent to the following line of code.

.center{

margin:0 auto;

}

I found that it is not centered in IE. I suggest you check if you have missed the DTD statement.

Method 2:

margin-left:50%;

left: -width/2;

Here The width is not the Width in CSS, but the width of your DIV. For example, if your div is 768px wide, then you should set left:-384px.

The second method sometimes encounters browser compatibility issues.

Method 3:

Apply the following style to the body:

body {text-align: center;}

This sentence will be within the body area All text content of is centered.

In order to facilitate control, please add the text-align: left; setting to the corresponding DIV to make relevant adjustments.

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