Set background image according to screen resolution

后端 未结 7 720
北恋
北恋 2020-12-12 21:57

I would like to be able to change my webpage background image according to the screen resolution the user uses so:

if screen resolution is greater than or equal to 1

7条回答
  •  盖世英雄少女心
    2020-12-12 22:12

    I know it's too old question but thought to answer, it might will help someone. If you see twitter, you will find something very tricky but pure css approach to achieve this.

    Applied CSS .background { background: none repeat scroll 0 0 #FFFFFF; height: 200%; left: -50%; position: fixed; width: 200%;} .background img{ bottom: 0; display: block; left: 0; margin: auto; min-height: 50%; min-width: 50%; right: 0; top: 0;}

    This background images fits to all size. even portrait view of ipad. it always adjust the image in center. if you zoom out; image will remain the same.

提交回复
热议问题