雪碧圖background-position的rem用法

看風景就發表於2018-07-27

background的雪碧圖配合rem就正常寫即可,要加上background-size,大小為sprites的原圖尺寸,寬高為一幀的尺寸。
例如:

.player{
    width: 2.32rem; /*一幀圖的大小*/
    height: 2.8133rem;
    display: inline-block;
    position: absolute;
    left: 50%;
    margin-left: -1.16rem;
    z-index: 10;
    background:url('../images/activity_redrain_aug/player_sprites.png') no-repeat;
    background-size: 7.76rem 6.24rem; /*此處寫sprites的原圖大小,不是一幀的大小*/
}
.player0 {
    background-position:  -0.1333rem -0.1333rem;
}
.player1{
    background-position: -2.72rem -0.1333rem;
}
.player2{
    background-position: -5.3067rem -0.1333rem;
}
.player3{
    background-position: -0.1333rem -3.2133rem;
}

 

相關文章