Stretch and scale CSS background

前端 未结 16 2026
难免孤独
难免孤独 2020-11-22 02:28

Is there a way to get a background in CSS to stretch or scale to fill its container?

16条回答
  •  攒了一身酷
    2020-11-22 03:07

    Use the CSS 3 property background-size:

    #my_container {
        background-size: 100% auto; /* width and height, can be %, px or whatever. */
    }
    

    This is available for modern browsers, since 2012.

提交回复
热议问题