Div Center Code Div Horizontal Center Display CSS Code

Source: Internet
Author: User

How do I use CSS to center the Div, and what CSS styles are there to center the div horizontally?

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.

The example explains the 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 to 400px, height is 100px, the border is red. So that we can observe the effect.

  2. <html>
  3. <head>
  4. <Meta charset="utf-8" />
  5. <title></title>
  6. <style>
  7. body{Text-align:center}
  8. . div{margin:0 Auto; width:400px; height:100px; border:1px Solid #F00}
  9. /* CSS Comment: Set the width border height style for the effect of viewing */
  10. </style>
  11. </head>
  12. <body>
  13. <div class="div">
  14. DIVCSS5 instances
  15. </div>
  16. </body>
  17. </html>

Div Center Code Div Horizontal Center Display CSS Code

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.