2017-01-06 1 views
0

J'ai ce texte en haut d'une image. Lorsque je survole le texte, le survol que j'ai créé pour l'image d'arrière-plan ne fonctionne pas. Quelqu'un aurait-il une solution pour cela?Le texte sur l'image d'arrière-plan supprime son état stationnaire

jsFiddle: https://jsfiddle.net/marineboudeau/h177pdne/4/

<div class="card"> 
    <a href="#"> 
    <div class="background-container"> 
     <div class="background" style="background: url('https://unsplash.it/300/200/?random') no-repeat; background-size: cover; background-position: center;"></div> 
    </div> 
    </a> 
    <a href="#" class="headline link--no-decor"> 
    <h2>Headline</h2> 
    </a> 
</div> 

Et le CSS:

.card { 
    width: 300px; 
    height: 200px; 
} 

a { 
    text-decoration: none; 
} 

h2 { 
    color: white; 
    font-family: Helvetica, sans-serif; 
} 

h2:hover { 
    color: yellow; 
} 

.headline { 
    padding: 0 22px; 
    position: relative; 
    margin-top: -80px; 
    display: flex; 
    flex-direction: row; 
    align-items: center; 
} 

.background-container { 
    top: 0; 
    left: 0; 
    width: 100%; 
    height: 100%; 
    display: block; 
    position: relative; 
} 

.background-container:after { 
    content: "gradient mask for image"; 
    overflow: hidden; 
    position: absolute; 
    text-indent: -9999rem; 
    font-size: 0; 
    line-height: 0; 
    top: 0; 
    bottom: 0; 
    left: 0; 
    right: 0; 
    background: linear-gradient(20deg ,rgba(0,0,0,.8), rgba(0,0,0,0)); 
} 

.background-container:hover:after { 
    background: linear-gradient(20deg,rgba(255, 0, 0,.6),rgba(255, 255, 0,.6)); 
    border: 2px solid red; 
} 

.background { 
    height: 200px; 
} 

Merci!

Répondre

2

Déplacez <a href="#" class="headline link--no-decor"> dans l'élément backround, afin qu'il ne bloque pas l'événement hover.

Pour éviter que le .background-container:after du bloc du vol stationnaire a.headline, nous devons assigner position: relative et z-index: 1-a.headline.

.card { 
 
    width: 300px; 
 
    height: 200px; 
 
} 
 

 
a { 
 
    text-decoration: none; 
 
} 
 

 
h2 { 
 
    color: white; 
 
    font-family: Helvetica, sans-serif; 
 
} 
 

 
h2:hover { 
 
    color: yellow; 
 
} 
 

 
.headline { 
 
    position: relative; 
 
    z-index: 1; 
 
    padding: 0 22px; 
 
    position: relative; 
 
    margin-top: -80px; 
 
    display: flex; 
 
    flex-direction: row; 
 
    align-items: center; 
 
} 
 

 
.background-container { 
 
    top: 0; 
 
    left: 0; 
 
    width: 100%; 
 
    height: 100%; 
 
    display: block; 
 
    position: relative; 
 
} 
 

 
.background-container:after { 
 
    content: "gradient mask for image"; 
 
    overflow: hidden; 
 
    position: absolute; 
 
    text-indent: -9999rem; 
 
    font-size: 0; 
 
    line-height: 0; 
 
    top: 0; 
 
    bottom: 0; 
 
    left: 0; 
 
    right: 0; 
 
    background: linear-gradient(20deg ,rgba(0,0,0,.8), rgba(0,0,0,0)); 
 
} 
 

 
.background-container:hover:after { 
 
    background: linear-gradient(20deg,rgba(255, 0, 0,.6),rgba(255, 255, 0,.6)); 
 
    border: 2px solid red; 
 
} 
 

 
.background { 
 
    height: 200px; 
 
}
<div class="card"> 
 
    <a href="#"> 
 
    <div class="background-container"> 
 
     <div class="background" style="background: url('https://unsplash.it/300/200/?random') no-repeat; background-size: cover; background-position: center;"></div> 
 
     <a href="#" class="headline link--no-decor"> 
 
     <h2>Headline</h2> 
 
     </a> 
 
    </div> 
 
    </a> 
 
</div>

+0

Oh duh. Je vous remercie! – Imalea

1

Istead de mettre en vol stationnaire sur le .background-container:hover:after ajouter vol stationnaire sur ce sélecteur .card:hover et sélectionnez arrière-plan cointainer comme celui-ci .card:hover a .background-container:after

Cela devrait fonctionner,

.card:hover a .background-container:after { 
     background: linear-gradient(20deg,rgba(255, 0, 0,.6),rgba(255, 255, 0,.6)); 
     border: 2px solid red; 
} 

Vérifier sur le code complet

.card { 
 
    width: 300px; 
 
    height: 200px; 
 
} 
 
a { 
 
    text-decoration: none; 
 
} 
 
h2 { 
 
    color: white; 
 
    font-family: Helvetica, sans-serif; 
 
} 
 
h2:hover { 
 
    color: yellow; 
 
} 
 
.headline { 
 
    padding: 0 22px; 
 
    position: relative; 
 
    margin-top: -80px; 
 
    display: flex; 
 
    flex-direction: row; 
 
    align-items: center; 
 
} 
 
.background-container { 
 
    top: 0; 
 
    left: 0; 
 
    width: 100%; 
 
    height: 100%; 
 
    display: block; 
 
    position: relative; 
 
} 
 
.background-container:after { 
 
    content: "gradient mask for image"; 
 
    overflow: hidden; 
 
    position: absolute; 
 
    text-indent: -9999rem; 
 
    font-size: 0; 
 
    line-height: 0; 
 
    top: 0; 
 
    bottom: 0; 
 
    left: 0; 
 
    right: 0; 
 
    background: linear-gradient(20deg, rgba(0, 0, 0, .8), rgba(0, 0, 0, 0)); 
 
} 
 
.card:hover a .background-container:after { 
 
    background: linear-gradient(20deg, rgba(255, 0, 0, .6), rgba(255, 255, 0, .6)); 
 
    border: 2px solid red; 
 
} 
 
.background { 
 
    height: 200px; 
 
}
<div class="card"> 
 
    <a href="#"> 
 
    <div class="background-container"> 
 
     <div class="background" style="background: url('https://unsplash.it/300/200/?random') no-repeat; background-size: cover; background-position: center;"></div> 
 
    </div> 
 
    </a> 
 
    <a href="#" class="headline link--no-decor"> 
 
    <h2>Headline</h2> 
 
    </a> 
 
</div>