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