How to stretch the background image to fill a div

后端 未结 10 1150
慢半拍i
慢半拍i 2020-12-04 10:27

I want to set a background image to different divs, but my problems are:

  1. The size of image is fixed(60px).
  2. Varying div\'s size

How

10条回答
  •  爱一瞬间的悲伤
    2020-12-04 11:09

    For this you can use CSS3 background-size property. Write like this:

    #div2{
        background-image:url(http://s7.static.hootsuite.com/3-0-48/images/themes/classic/streams/message-gradient.png);
        -moz-background-size:100% 100%;
        -webkit-background-size:100% 100%;
        background-size:100% 100%;
        height:180px;
        width:200px;
        border: 1px solid red;
    }
    

    Check this: http://jsfiddle.net/qdzaw/1/

提交回复
热议问题