2017-10-18 7 views
0

J'ai actuellement le fond de ma section supérieure fixe, et la section en dessous défile au-dessus de l'arrière-plan. Le problème est que lorsque je défile, le texte de l'arrière-plan de la section supérieure défile, mais j'aimerais qu'il soit corrigé en arrière-plan tout en étant réactif au bootstrap. Voici mon code:Comment rendre le texte et le bouton fixes en arrière-plan lors de l'utilisation de l'effet de parallaxe

.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>

Répondre

0

Essayez ceci,

ajouter position: fixed; à la rubrique topInfoText et margin-top: 100vh à bouton 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 here