How to set a minimum width with background-size

后端 未结 4 556
伪装坚强ぢ
伪装坚强ぢ 2021-01-04 06:46

I have an image that is 1000px X 600px . I want to use it as a responsive background for a div but would like to set a minimum width of 1000px despite how small the browser

4条回答
  •  南方客
    南方客 (楼主)
    2021-01-04 06:52

    There's now an option for background-size to only scale the image until the picture has met it actual height/width. This way, you don't have to set a min-width or anything.

    In your CSS:

    body {
      background-size: cover;
    }
    

    Reference: https://developer.mozilla.org/en-US/docs/Web/CSS/background-size#Values

提交回复
热议问题