>我目前修复了顶部背景,下方的部分滚动在背景顶部。问题是,当我滚动时,顶部背景上的文本会滚动,但我希望它被固定在背景上,同时仍然具有引导响应。这是我的代码:
.topInfo {
background-image: linear-gradient( rgba(0, 0, 0, .25), rgba(0, 0, 0, .25)), url('/CMS_Static/Uploads/313864614C6F6F/exuma rocks 2.jpg');
background-attachment: fixed;
background-size: cover;
background-repeat: no-repeat;
background-position: center;
height: 100%;
}
.topInfoText {
color: white;
padding-top: 275px;
font-size: 3.3em;
}
.bannerBtn {
border-style: solid;
border-width: 2px;
border-color: #ffffff;
border-radius: 50px;
padding-top: 15px;
padding-bottom: 15px;
margin-top: 130px;
font-size: 1.45em;
color: #ffffff;
font-weight: 700;
transition: all 0.3s ease-in-out 0s;
}
<section class="topInfo">
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<h1 class="topInfoText text-center">Aerial Drone Services and Stock Footage</h1>
</div>
<div class="col-sm-4 col-sm-offset-4">
<a class="btn bannerBtn btn-block" href="#">Learn More</a>
</div>
</div>
</div>
</section>
试试这个,
将position: fixed;
添加到标题topInfoText
,margin-top: 100vh
按钮bannerBtn
。
body {
background: #333;
}
.topInfo {
background-image: linear-gradient( rgba(0, 0, 0, .25), rgba(0, 0, 0, .25)), url('image here');
background-attachment: fixed;
background-size: cover;
background-repeat: no-repeat;
background-position: center;
}
.topInfoText {
color: white;
padding-top: 275px;
font-size: 3.3em;
position: fixed; /* Change */
}
.bannerBtn {
border-style: solid;
border-width: 2px;
border-color: #ffffff;
border-radius: 50px;
padding-top: 15px;
padding-bottom: 15px;
margin-top: 130px;
font-size: 1.45em;
color: #ffffff;
font-weight: 700;
transition: all 0.3s ease-in-out 0s;
margin-top: 100vh; /* Change */
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" rel="stylesheet"/>
<section class="topInfo">
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<h1 class="topInfoText text-center">Aerial Drone Services and Stock Footage</h1>
</div>
<div class="col-sm-4 col-sm-offset-4">
<a class="btn bannerBtn btn-block" href="#">Learn More</a>
</div>
</div>
</div>
</section>
jsfiddle 在这里