How to set a minimum width with background-size

后端 未结 4 571
伪装坚强ぢ
伪装坚强ぢ 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 07:16

    You can use calc in background-size:

    .bg {
        background-size: calc(max(100%, 1000px));
    }
    

    calc works also with background-position, for one side, or both sides

提交回复
热议问题