简体   繁体   English

放大网页时出现问题

[英]Issue when zooming on web page

When I zoom in and out of my page the elements get weird. 当我放大和缩小页面时,元素变得很奇怪。

Everything works but a container div (which is a color overlay over the image background). 除了容器div(在图像背景上覆盖颜色)之外,其他所有内容都可以正常工作。 When you zoom in, or you go to mobile the div does not continue to the bottom of the page like it should. 放大或转到移动设备时,div不会像应有的那样继续到达页面底部。 Instead, it shows the background image at the bottom without the image overlay. 相反,它在底部显示背景图像而没有图像覆盖。

Code: 码:

#container {
  height:100%;
  width:100%;
  position: relative;
  background-color: rgba(0,0,0,.5);
  position: fixed;
}

body {
  background-image: url(../img/d2.jpg);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  background-attachment: fixed;
}

HTML: HTML:

<div id="container">
    <div class="block">
         Content
    </div>       
</div>

I already tried the 100% height property on the overlay, and it didn't work. 我已经在叠加层上尝试了100%height属性,但是它不起作用。 This is particularly an issue with mobile as well. 对于移动设备,这也是一个特别的问题。

问题可能出在您执行此操作的方式上,css将容器显示为高度和宽度为100%,但是(取决于您对html的结构方式),容器只会占到100%浏览器窗口,而不是网页本身。

I think fixing your CSS as Oscar suggested is a good starting point. 我认为按照Oscar的建议修复CSS是一个很好的起点。 Making that change, it seems like things are working correctly, but I'm a bit unclear on the issue. 进行更改后,看起来一切正常,但是我对此问题尚不清楚。

#container {
  height:100%;
  width:100%;
  position: relative;
  background-color: rgba(0,0,0,.5);
  position: fixed;
}

body {
  background-image: url('http://www.wallpick.com/wp-content/uploads/2013/11/Smokey-Abstract-Wallpaper-Wallpaper-HD.jpg');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  background-attachment: fixed;
}

JSFiddle JSFiddle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM