问题描述
我的网站背景是覆盖整个网页的巨大图片,我该如何做到这一点,以便我们检测用户的屏幕大小并相应地更改背景图片?
例如,我的背景图像是1x1px,如果用户屏幕是2x2px(这只是一个例子,没有人有这种小屏幕),我想伸展我的背景以适应2x2。如果用户屏幕是0.5x0.6px,那么我希望我的背景仅显示其0.5x0.6px部分,而不显示整个1x1px。 解析方案
使用图片标签作为背景,为宽度和<$给它一个 100% c $ c> height ,并用 z-index 给所有内容设置它,给它绝对在您需要的位置放置并设置其顶部和左。
< img src =yourimagewidth =100%height =100%style =z-index:0/> b
$ bMy website's background is a huge image that covers the whole webpage, how can I make it so that, we detect user's screen size and change the background image accordingly?
Say for example, my background image is 1x1px, if user screen is 2x2px (this is just an example, nobody has this kind of small screen), I want stretch my background to fit 2x2. If user screen is say, 0.5x0.6px, then I want my background to be shown only its 0.5x0.6px part, not the whole 1x1px.
解决方案Use an image tag as the background give it a 100% for width and height, and set it behind all of the content with z-index give it absolute positioning and set its top and left where you need it to be.
<img src="yourimage" width="100%" height="100%" style="z-index:0"/>这篇关于背景图像更改与屏幕大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!