css - 背景图像在移动屏幕上显示为放大
问题描述
我正在为学校构建一个项目,但背景图像有问题。我已经使用这个代码片段来做到这一点(https://css-tricks.com/perfect-full-page-background-image/),它在桌面和 Chrome 开发工具上运行良好(对于移动设备,是)。当我在手机上的 Chrome 或 Safari 上打开我的网站时,它无法正常工作。截图如下:
这是我在 CSS 上的代码:
.container-hero {
height: 100vh;
width: 100%;
background: url("../images/hero-image.jpg") no-repeat center center fixed;
background-size: cover;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
}
<div class="container-fluid container-hero">
<div class="row">
<div class="col-12">
<div class="hero-j jumbotron text-center text-uppercase text-white">
<div class="container">
<h1 class="display-4 section-header">Be a hero.</h1>
<hr class="block-divider--white">
<p class="hero-j text"> At Doug's, we <strong>Evolve</strong> together.</p>
<a href="#signup" class="btn btn-lg button-signup">
Sign me up!
</a>
</div>
</div>
</div>
</div>
</div>
我非常感谢您的帮助!
解决方案
IOS Safari,因此 IOS Chrome,不支持固定在后台。请参阅https://caniuse.com/?search=fixed
我用我自己的图像尝试了你的 CSS,它很模糊。从这个声明中去掉固定就很清楚了。
background: url("https://ahweb.org.uk/gear.jpg") no-repeat center center;
在不知道代码的确切布局的情况下,很难知道这是否足够,或者您是否必须将图像取出作为另一个容器的背景,以便在需要时始终保持在视图中。
推荐阅读
- linux - 如何使用 sed 替换匹配的列表
- validation - 尝试使用 null 输入验证 TextFormField 但它不起作用并在 Flutter 中弹出一些奇怪的错误 [PS: Still a learner]
- javascript - AngularJS 选项列表更改 URL
- python - 为什么我不能从另一个派生 Cython cdef 扩展类型?
- python - 如何关闭scrapy的ImagesPipeline自动创建完整文件夹?
- angular - “请求”类型的参数不可分配给“HttpRequest”类型的参数
' - dynamics-crm - Dynamics 365 8.2(本地)中的实体更改跟踪
- laravel - 如何在十月 CMS 中创建自己的函数?
- c# - 什么是 OData 控制器生命周期事件 OnExecuting / OnExecuted?
- android - 使用接近 SDK 检测单个信标