垂直居中

1.line-height

html :css

div.parent
    div.child

css :html

.parent
    height 736px
    line-height @height

2.display: table

html :web

div.parent
    div.child

css : flex

.parent
    display table
.child
    display table-cell
    vertical-align middle

3.position

html :code

div.parent
    div.child

css :orm

.parent
    position relative        
.child
    position absolute
    top 50%
    height 736px
    margin-top -(@height / 2)

4.position

html :htm

div.parent
    div.child

css : it

.parent
    position relative
.child
    position absolute
    top 0
    bottom 0
    margin auto

5.padding

html : io

div.parent
    div.child

css : table

.parent
    padding 5% 0
.child
    padding 10% 0

6.float

html :

div.parent
    div.floater
    div.child

css :

html, body
    height 100%       
    .parent 
        height @height
    .floater
        float left
        height @height / 2
        width @height
        margin-bottom -50px
    .child
        clear both
        height 100px

7. :before

要求display inline-block
html :

div.parent
    div.child

css :

.parent:before 
    content ''
    display inline-block
    height 100%
    vertical-align middle
.child
    display inline-block
    vertical-align middle

8.translate

html :

div.parent
        div.child

css :

.parent            
    height 100%
    position relative
    .child    
        position absolute
        top @height / 2
        transform translateY(-50%)

9. display: box

html :

div.parent
    div.chlid

css :

.parent
    display -webkit-box
    -webkit-box-align center

10.flex

html :

div.parent
    div.child

css :

.parent
    display flex
    align-items center
相關文章
相關標籤/搜索