background-size in shorthand background property (CSS3)

前端 未结 5 1297
再見小時候
再見小時候 2020-11-28 23:12

I\'m trying to mix background-image and background-size properties in a shorthanded background property. Based on W3C documentation

5条回答
  •  孤街浪徒
    2020-11-28 23:36

    Just a note for reference: I was trying to do shorthand like so:

    background: url('../images/sprite.png') -312px -234px / 355px auto no-repeat;
    

    but iPhone Safari browsers weren't showing the image properly with a fixed position element. I didn't check with a non-fixed, because I'm lazy. I had to switch the css to what's below, being careful to put background-size after the background property. If you do them in reverse, the background reverts the background-size to the original size of the image. So generally I would avoid using the shorthand to set background-size.

    background: url('../images/sprite.png') -312px -234px no-repeat;
    background-size: 355px auto;
    

提交回复
热议问题