【发布时间】:2018-06-04 22:29:20
【问题描述】:
我使用 HTML 和 CSS 编写响应式网站。我使用 Bootstrapper 框架。
我的问题:当我使用 100% 作为背景图像时,图像不会到达桌面屏幕上的页面末尾(因为以 100% 高度缩放的图像小于显示器结果)。在 iPhone (Safari) 上看起来不错。页脚将位于图像下方。
当我使用 Viewport-value 100vh 时,桌面屏幕上的结果看起来不错(图像将填充背景),但在移动设备 (iPhone) 上,文本将与页脚重叠。看起来很可怕。
我正在寻找一种解决方案,例如:在台式机上使用 100vh,在移动设备上使用 100%。这可能吗?
HTML 代码:
<section id="myid">
<div class="myclass">
<div class="container">
<div class="row">
<div class="col-md-8 opaline">
<div class="row">
<div class="col-md-10 col-md-offset-1">
<p>Great Content</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
<footer>
<div class="container">
<div class="row">
<div class="col-md-10">
<p>Great Footer Content</p>
</div>
</div>
</div>
</footer>
CSS:(移动浏览器上的OK-Result)
.myclass {
/* The image used */
background: linear-gradient( rgba(33, 37, 43, 0.6), rgba(33, 37, 43, 0.1) ), url(/images/image.jpg);
background-position: center;
background-repeat: no-repeat;
background-size: cover;
height: 100%;
padding-top: 36px;
}
CSS:(桌面浏览器上的 OK-Result)
.myclass {
/* The image used */
background: linear-gradient( rgba(33, 37, 43, 0.6), rgba(33, 37, 43, 0.1) ), url(/images/image.jpg);
background-position: center;
background-repeat: no-repeat;
background-size: cover;
height: 100vh;
padding-top: 36px;
}
我也玩过 calc 函数 - 没有成功:
height: calc(100vh - 000px);
【问题讨论】:
-
对两者都使用 100% 并设置为 min-height:100vh,会产生您想要的结果吗?
标签: html ios css viewport responsive