【发布时间】:2020-12-04 17:26:43
【问题描述】:
我正在为学校构建一个项目,但我遇到了背景图片问题。我已使用此代码 sn-p 来执行此操作(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>
非常感谢您的帮助!
【问题讨论】:
-
您也可以发布您的 HTML 代码吗?另外,您希望您的背景在移动设备上看起来是什么样的?
-
您好,您使用的是什么手机、操作系统和浏览器版本?
-
大家好,我已经在 CSS 上添加了关于该类的 html div - 希望这会有所帮助!
标签: css background-image viewport