Reputation: 2063
I've set up some image hover styling based on this tutorial which creates the hover styling using the before
and after
pseudo-elements.
Works (and looks) great but I need to be able to insert buttons/links within the hover content but due to this being styled on the pseudo-elements, the after
is preventing the buttons/links to be clickable.
It looks like the below, I've set up a jsfiddle to demonstrate what I am wanting to do - as you'll notice, the link isn't clickable on hover and I'm wondering if anyone can suggest a simple way of making this link clickable without having to completely change the way this is structured.
.media {
display: inline-block;
position: relative;
vertical-align: top;
}
.media__image { display: block; }
.media__body {
background: rgba(41, 128, 185, 0.7);
bottom: 0;
color: white;
font-size: 1em;
left: 0;
opacity: 0;
overflow: hidden;
padding: 3.75em 3em;
position: absolute;
text-align: center;
top: 0;
right: 0;
-webkit-transition: 0.6s;
transition: 0.6s;
}
.media__body:hover { opacity: 1; }
.media__body:after,
.media__body:before {
border: 1px solid rgba(255, 255, 255, 0.7);
bottom: 1em;
content: '';
left: 1em;
opacity: 0;
position: absolute;
right: 1em;
top: 1em;
-webkit-transform: scale(1.5);
-ms-transform: scale(1.5);
transform: scale(1.5);
-webkit-transition: 0.6s 0.2s;
transition: 0.6s 0.2s;
}
.media__body:before {
border-bottom: none;
border-top: none;
left: 2em;
right: 2em;
}
.media__body:after {
border-left: none;
border-right: none;
bottom: 2em;
top: 2em;
}
.media__body:hover:after,
.media__body:hover:before {
-webkit-transform: scale(1);
-ms-transform: scale(1);
transform: scale(1);
opacity: 1;
}
.media__body h2 { margin-top: 0; }
.media__body p { margin-bottom: 1.5em; }
<div class="media">
<img class="media__image" src="http://lorempixel.com/400/300/animals" alt="" />
<div class="media__body">
<h2>Cool Title</h2>
<p>Lorem ipsum dolor sit amet, <a href="/mylink">consectetur adipisicing</a> elit. Nesciunt laboriosam voluptatem necessitatibus cum, tenetur repellat, eaque eos debitis! Quaerat.</p>
</div>
</div>
Upvotes: 1
Views: 1498
Reputation: 123397
A CSS3
-only (actually moved into CSS4
specs) solution would be the pointer-events
property, e.g.
.media__body:hover:after,
.media__body:hover:before {
...
pointer-events: none;
}
supported on all modern browser but only from IE11
(on HTML/XML content)
Example: http://jsfiddle.net/8uz7mx6h/
Another solution, supported also on older IE, is to apply position: relative
with a z-index
to the paragraph, e.g.
.media__body p {
margin-bottom: 1.5em;
position: relative;
z-index: 1;
}
Example: http://jsfiddle.net/0nrbjwmg/2/
Upvotes: 6
Reputation: 2558
.media__body p { margin-bottom: 1.5em;
position: relative;
z-index:999;
}
try this !
Upvotes: 1