CSS: Scale background image down if larger than window, keep at 100% otherwise

后端 未结 4 2044
灰色年华
灰色年华 2021-01-12 09:08

I\'d like to deploy a background image in the body of my website that scales down with the window resolution, but does not scale up beyond it\'s original size (1920x1080). T

4条回答
  •  再見小時候
    2021-01-12 09:43

    I would use a div as a wrapper with a max-width and set the background to that div.

    HTML

    
     
    Content

    CSS

    .container {
      width: 100%;
      max-width: 1920px; /* YOUR BG MAX SIZE */
      background:url("bg.png") no-repeat;
      background-size: 100%;
    }
    

提交回复
热议问题