How CSS makes the div layer centered _css/html

Source: Internet
Author: User
How to center the DIV
The main style definitions are as follows:

body {text-align:center;}
#center {Margin-right:auto; Margin-left:auto; }
Description

The text-align:center is defined first in the parent element, which means that the content within the parent element is centered, and the setting for IE is already available. But it can't be centered in Mozilla. The solution is to add "Margin-right:auto" when the child element is defined; Margin-left:auto; ”

It should be explained that if you want to use this method to make the whole page to center, it is recommended not to set in a Div, you can split the div in turn, as long as in each of the split Div defined margin-right:auto; Margin-left:auto; You can do it.

How do I make a picture center vertically in a div
Use the background method. Example:

Body{background:url (http://www.w3cn.org/style/001/logo_w3cn_194x79.gif) #FFF No-repeat Center;}
The key is the final center, which defines the position of the picture. It can also be written as "top left" or "bottom right", or write the value "50 30".

The effect is as follows:

How do I make text vertically centered in a div
If it is text, you can not use the background method, the way to increase the line spacing to achieve vertical center, the complete code is as follows:






Test content




Description

Vertical-align:middle the vertical center of the row, we increase the line spacing to as high as the entire Div, and then insert the text in the vertical center of the line-height:200px.

  • 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.