抱歉,这个愚蠢的问题已经被问了很多,但是我阅读和测试过的解决方案都没有对我有用......
我正在尝试用旋转木马背景创建那种视差效果:https ://www.w3schools.com/howto/tryhow_css_parallax_demo.htm 这是给我父亲的网站的,我想给他这个周末的礼物(HB爸爸!)
这是我的代码:
html {
font-family: sans-serif;
line-height: 1.15;
-webkit-text-size-adjust: 100%;
-ms-text-size-adjust: 100%;
-ms-overflow-style: scrollbar;
-webkit-tap-highlight-color: transparent;
height: 100%;
}
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
font-size: 1rem;
font-weight: 400;
line-height: 1.5;
color: #212529;
text-align: left;
background-color: #fff;
height: 100%;
}
.carousel-item {
height: 75vh;
min-height: 500px;
background: no-repeat center center scroll;
background-attachment: fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
background-position: center;
background-repeat: no-repeat;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>Half Slider - Start Bootstrap Template</title>
<!-- Bootstrap core CSS -->
<link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="css/half-slider.css" rel="stylesheet">
</head>
<body>
<header>
<div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>
<li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
<li data-target="#carouselExampleIndicators" data-slide-to="2"></li>
</ol>
<div class="carousel-inner" role="listbox">
<!-- Slide One - Set the background image for this slide in the line below -->
<div class="carousel-item active" style="background-image: url('img/slide1.jpg')">
</div>
<!-- Slide Two - Set the background image for this slide in the line below -->
<div class="carousel-item" style="background-image: url('img/slide22.jpg')">
</div>
<!-- Slide Three - Set the background image for this slide in the line below -->
<div class="carousel-item" style="background-image: url('img/slide3.jpg')">
</div>
</div>
<a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</header
<!-- Page Content -->
<div class="jumbotron">
<h1 class="text-center">SARL COQUILLE</h1>
</div>
<!-- rest of my html -->
</body>
</html>
我用这个模板开始了我的项目(如果它有帮助的话),只是希望页面内容与标题重叠:https ://blackrockdigital.github.io/startbootstrap-half-slider/
问题:图像在 ~0.5scd 之后被调整为视口大小
经过测试的解决方案:使用位置而不是背景位置,调整我的图像大小(1900 * 1080),背景尺寸:自动 100%,其他一些我忘记了(对不起!)
一个奇怪的行为:(对我来说很奇怪,因为我是菜鸟)第一张图片以完美的比例加载
谁能给我一条建议?我已经阅读/观看了不同的教程,但对我没有任何帮助,我还阅读了 W3School 文档,但它并没有真正帮助我......
对不起我糟糕的英语!