Using CSS to achieve a div horizontal center display

Source: Internet
Author: User
How do I use CSS to center the div display? For everyone to do a simple code, the use of CSS to achieve a div horizontal center display, the need for friends can learn from reference.

The main CSS code needed is two, one is text-align:center (content Center), the other is margin:0 auto, and its two styles need to be used in order to achieve the center display layout of Div box.

First we set the body Text-align:center, and then the need to center the Div box set CSS style margin:0 auto, so that the corresponding Div horizontal center.

Div Center Code application, in order to observe the DIV center effect, we set a div to the div named ". Div" in the HTML div tag using class= "DIV", set its width is 400px, height is 100px, the border is red. So that we can observe the effect.

1. Complete HTML+CSS Code

<! DOCTYPE html> 

2, Div+css Center instance

Div CSS for center effect

Div for center effect

3, Div Center code application features

This centering method is to make the DIV center effect perfectly compatible with the major platforms, compatible with the major browsers, regardless of the high version ie or high version of IE are compatible.

This is the way to achieve a div horizontal center display using CSS.

Related reading:

How HTML turns into a TXT file


How to set a table border on table and TD background


for table and TD tricks

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.