Align vertically using CSS 3

后端 未结 8 1191
忘了有多久
忘了有多久 2020-11-30 19:21

With CSS 3, are there any way to vertically align an block element? Do you have an example? Thank you.

8条回答
  •  隐瞒了意图╮
    2020-11-30 19:30

    a couple ways:

    1. Absolute positioning-- you need to have a declared height to make this work:

    Hey
    div {height: 100%; width: 100%; position: relative} div.center { width: 100px; height: 100px; top: 50%; margin-top: -50px; }

    *2. Use display: table http://jsfiddle.net/B7CpL/2/ *

    text centered with image
    div { display: table; vertical-align: middle } div img, div.text { display: table-cell; vertical-align: middle }
    1. A more detailed tutorial using display: table

    http://css-tricks.com/vertically-center-multi-lined-text/

提交回复
热议问题