Set size on background image with CSS?

后端 未结 18 1685
野性不改
野性不改 2020-11-22 12:38

Is it possible to set the size of the background image with CSS?

I want to do something like:

background: url(\'bg.gif\') top repeat-y;
background-si         


        
18条回答
  •  深忆病人
    2020-11-22 13:05

    You totally can with CSS3:

    body {
        background-image: url(images/bg-body.png); 
        background-size: 100%; /* size the background image at 100% like any responsive img tag */
        background-position: top center;
        background-repeat:no-repeat;
     }
    

    This will size a background image to 100% of the width of the body element and will then re-size the background accordingly as the body element re-sizes for smaller resolutions.

    Here is the example: http://www.sccc.premiumdw.com/examples/resize-background-images-with-css/

提交回复
热议问题