@dudusky
2017-03-03T11:12:19.000000Z
字数 1550
阅读 506
by Dudusky
graph LR;A[Hard edge]-->|Link text|B(Round edge);B-->C{Decision};C-->|One|D[Result one];C-->|Two|E[Result two];
* This will work for inline, inline-block,inline-table,inline-flex.- - -#### 2. Is it a block level element?* You can center a block-level element by giving it margin-left and margin-rifht of auto (ant it has a set width,otherwise it would be full width and wouldn't need centering).That's often done with shorthand like this:```css.center-me {margin: 0 auto;}
If you have two or more block-level elements that need to be centered horizontally in a row, chances are you"d better served making them a differen display type.Here"s an example of making them inline-block and an example of flexbox:
~~~css
.inline-block-center {
text-align: center;
}
.inline-block-center div {
display: inline-block;
}
.flex-center {
display: flex;
justify-content: center;
}
~~~
Multiple block level elements stacked on top of each other, in which case auto margin technique is still fine:
main div {maring: 0 auto;}
Sometimes inline/text elements can appear vertically centered, just because there is equal padding about and below them,like this:
~~~css
.link {
padding-top: 30px;
padding-bottom: 30px;
}
~~~