CSS Notes 2

Source: Internet
Author: User

Horizontal center Setting-inline element Text-align:center

If the element is set as an inline element in text, picture, and so on, the horizontal center is set by the parent element .text-align:center

Horizontal Center Setting-Fixed width block element margin:0 auto;

Elements that satisfy the fixed width and block two conditions can be centered by setting the "left margin" value to "auto".

Horizontal Center Summary-variable width block element method (i) table{margin:0 Auto}

First step: Add a table label (including <tbody>, <tr>, <td>) to the center of the element you want to set.

Step two: Set the "left and right margin center" for this table (this is the same as for a fixed-width block element).

Horizontal Center Summary-Indefinite wide block element Method (ii) Text-align:center;display:inline;

The second method: Change the dispaly of the block-level element to the inline type, and then use the Text-align:center to achieve the center effect

Horizontal Center Summary-variable width block element method (iii)

Method Three: By setting float for the parent element and then setting position:relative and left:50% for the parent element, the child elements are set position:relative and left:-50% to achieve horizontal centering.

Center vertically-single line of text with parent element height determination

The height of the parent element determines the vertical centering of a single line of text by setting the height of the parent element and the line-height to a high consistency.

Center vertically-multi-line text with parent element height determination (method one)

Use the Insert table (including TBODY, TR, TD) labels and set the Vertical-align:middle.

Vertical centering-Multi-line text (method two) Display:table-cell;vertical-align:middle of the parent element height determination;

In Chrome, Firefox and IE8 above the browser can be set block-level element display for Table-cell, activating vertical-align properties, but note IE6, 7 does not support this style.

Implicitly changing the display type

One interesting phenomenon is that when you set one of the following 2 sentences for an element (regardless of what type of element was previously, Display:none):

    1. Position:absolute
    2. Float:left or Float:right

The element automatically becomes display:inline-block, and of course you can set the width and height of the element and the default width does not fill the parent element

Article reference: http://www.imooc.com/code/6364

CSS Notes 2

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.