The beauty of CSS centering

Source: Internet
Author: User

What do you think about centering?

Div {margin: auto;}

A common centering method

Center horizontally

. Demo {    text-align: Center;      margin: auto;      position: absolute;      Left: 50%;      margin-left: -?px;}

Center vertically

. Demo {    height: 30px;     line-height: 30px;     display: Table-cell;      vertical-align: Middle;     position: absolute;      top: 50%;      margin-top: -?px;}

Is there any other way?

CSS3

Display:flex;

<!DOCTYPE HTML><HTML><Head><MetaCharSet=utf-8/></Head><Body>  <Divclass= "Flex">    <Divclass= "Flex-item">Flex Item</Div>  </Div></Body></HTML>
. Flex {  display: -webit-flex;   display: flex;   -webkit-align-items: Center;   align-items: Center;   Border: 1px solid;   height: 200px;} . Flex-item {  border: 1px solid Blue;   height: 50px;}

Center horizontally

{Alignment: center;}

Center vertically

{child-align: Middle;}

Position method

P {position:center;}

Fundamentals of CSS Theory

Box Model (box-sizing)

Border-box/content-box/padding-box

Positioning System
Normal stream (normal flow)
Block-level formatting context (block formatting contexts)
Inline formatting context (formatting contexts)
position:relative;
Floating (floats)
Absolute positioning (Absolute positioning)
Position:absolute;
position:fixed;

The essential work of the front end is "Restore Design"
And CSS is the ultimate realization of design intent

Three-layer separation (content, performance, behavior)
Graceful downgrade (Graceful degradation), 1994
Progressive Enhancement (Progressive enhancement), 2003

Misunderstanding

Misuse of the float layout
To close a float with an empty label
Control vertical spacing with <br>
With &nbsp; Control word spacing (justify layout, etc.)
Write a style directly on the label with the style property
Feel free to even use Pinyin to name Class,id
Multi-Class syndrome (abuse of OOCSS)

The beauty of CSS centering

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.