2017-04-21 5 views
2

Ich bin mir nicht sicher, was ich falsch mache, indem ich versuche, ein transparentes Overlay über einem Bild im Schwebeflug erscheinen zu lassen. Am Anfang versuchte ich einen Javascript-Ansatz, aber das hat nicht funktioniert, also dachte ich, ich würde einen leichteren CSS-Ansatz versuchen.Overlay über Bild bei Hover

Kann jemand sehen, warum das nicht funktioniert?

.section2-box { 
 
    display: inline-block; 
 
    width: 50%; 
 
    height: 50%; 
 
    border-bottom: 4px solid #FFF; 
 
    border-right: 4px solid #FFF; 
 
    box-sizing: border-box; 
 
    position: relative; 
 
} 
 
.fadeHover { 
 
    transition: all .35s ease; 
 
    -webkit-transition: all .35s ease; 
 
    transition-delay: 0.10s; 
 
    -webkit-transition-delay: 0.10s; 
 
    height: 100%; 
 
    width: 100%; 
 
    top: 0; 
 
    left: 0; 
 
    right: 0; 
 
} 
 

 
.fadeHover:hover .overlay { 
 
    background-color: rgba(0, 0, 0, 0.6); 
 
    z-index: 1; 
 
    height: 100%; 
 
    width: 100%; 
 
    top: 0; 
 
    left: 0; 
 
    right: 0; 
 
    position: absolute; 
 
    cursor: pointer; 
 
} 
 

 
.fadeHover-title { 
 
\t font-family: 'Raleway', sans-serif; 
 
\t font-weight: 600; 
 
\t font-size: 1.3rem; 
 
\t color: #FFF; 
 
\t display: none; 
 
} 
 
.fadeHover-title.activeHover { 
 
\t opacity: 1; 
 
} 
 
.fadeHover-description { 
 
\t font-size: 1.1rem; 
 
\t color: #FFF; 
 
\t font-family: 'Open Sans', sans-serif; 
 
\t display: none; 
 
} 
 
.fadeHover-description.activeHover { 
 
\t opacity: 1; 
 
} \t
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
 
<div class="section2-box fadehover" id="section2box3"> 
 
    <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/e/eb/Ash_Tree_-_geograph.org.uk_-_590710.jpg/220px-Ash_Tree_-_geograph.org.uk_-_590710.jpg"> 
 
    <div class="overlay"> 
 
    <h2 class="fadeHover-title">Option 1</h2> 
 
    <h3 class="fadeHover-description">Description</h3> 
 
    </div> 
 
</div>

+1

In Ihrem HTML heißt die Klasse 'fadehover'. In der CSS sein 'fadeHover'. Groß-/Kleinschreibung beachten ;-) – sn3ll

+1

@ sn3ll ha wow ... danke! Ich schlug mir dabei auf den Kopf und versuchte herauszufinden, warum es nicht funktionierte. Weißt du, wie ich den Text mit einem FadeIn-Ansatz zeigen könnte, ohne "Opazität" zu verwenden, weil darunter Elemente liegen? – Paul

+0

Opazität ist die einzige Möglichkeit, etwas zu verblassen ... – sn3ll

Antwort

2

Regardinf Ihre Frage auf den Kommentar: die Farbe des Elements ändern Text von einem rgba mit 0 alpha zu einem 1 alpha:

.section2-box { 
 
    display: inline-block; 
 
    width: 50%; 
 
    height: 50%; 
 
    border-bottom: 4px solid #FFF; 
 
    border-right: 4px solid #FFF; 
 
    box-sizing: border-box; 
 
    position: relative; 
 
} 
 
.fadeHover { 
 
    transition: all .35s ease; 
 
    -webkit-transition: all .35s ease; 
 
    transition-delay: 0.10s; 
 
    -webkit-transition-delay: 0.10s; 
 
    height: 100%; 
 
    width: 100%; 
 
    top: 0; 
 
    left: 0; 
 
    right: 0; 
 
} 
 

 
.fadeHover .overlay { 
 
    z-index: 1; 
 
    height: 100%; 
 
    width: 100%; 
 
    top: 0; 
 
    left: 0; 
 
    right: 0; 
 
    position: absolute; 
 
    cursor: pointer; 
 
} 
 

 
.fadeHover-title { 
 
\t font-family: 'Raleway', sans-serif; 
 
\t font-weight: 600; 
 
\t font-size: 1.3rem; 
 
\t color: rgba(255,255,255,0); 
 
    transition: color 0.5s; 
 
} 
 

 
.fadeHover:hover .fadeHover-title { 
 
\t color: rgba(255,255,255,1); 
 
} 
 
.fadeHover-description { 
 
\t font-size: 1.1rem; 
 
\t color: rgba(255,0,0,0); 
 
    transition: color 0.5s; 
 
} 
 
.fadeHover:hover .fadeHover-description { 
 
\t color: rgba(255,0,0,1); 
 
}
<div class="section2-box fadeHover" id="section2box3"> 
 
    <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/e/eb/Ash_Tree_-_geograph.org.uk_-_590710.jpg/220px-Ash_Tree_-_geograph.org.uk_-_590710.jpg"> 
 
    <div class="overlay"> 
 
    <h2 class="fadeHover-title">Option 1</h2> 
 
    <h3 class="fadeHover-description">Description</h3> 
 
    </div> 
 
</div>

+0

Perfekt. Danke für die Hilfe! – Paul