How to change background image based on screen size, possibly with Bootstrap

前端 未结 3 1964
南笙
南笙 2021-01-05 08:52

I have an background-image:url on my body in CSS. The problem is when I transition into mobile devices where the screen becomes portrait orientated

3条回答
  •  长发绾君心
    2021-01-05 09:12

    Use @media queries to write window size specific css. Example:

    @media (min-width: 400px) {
        .element {
            background: #cccccc;
        }
    }
    
    @media (min-width: 500px) {
        .element {
            background: #888888;
        }
    }
    
    @media (min-width: 600px) {
        .element {
            background: #222222;
        }
    }
    

    Here's is a Fiddle: http://jsfiddle.net/zhqn1vhh/

提交回复
热议问题