1.line-height

html :

div.parent
    div.child

css :

.parent
    height 736px
    line-height @height

2.display: table

html :

div.parent
    div.child

css :

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

3.position

html :

div.parent
    div.child

css :

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

4.position

html :

div.parent
    div.child

css :

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

5.padding

html :

div.parent
    div.child

css :

.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
        

charles
201 声望4 粉丝

« 上一篇
JavaScript基础
下一篇 »
vue 过渡 动画