How do I vertically center caption on img hover? - html

I am currently having problems centering my caption inside a div upon hover. The image inside the div is bigger than the div and I want the caption to be vertically centered inside that div?
HTML
<div class="container-fluid">
<div id="page">
<!-- GRID ITEM -->
<div class="item s1">
<a href="#">
<div class="grid-image">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/4/4e/Pleiades_large.jpg/1024px-Pleiades_large.jpg">
</div>
<div class="item-caption">
<h5>I want this to be center</h5>
</div>
</a>
</div>
<!-- /GRID ITEM -->
</div>
</div>
CSS
#page .item {
width: calc(16.66% - 10px);
display: inline-block;
height: 0;
float: left;
padding-bottom: 16.66%;
overflow: hidden;
background-color: salmon;
margin: 5px;
position: relative;
}
#page .item.s1 {
width: calc(50% - 10px);
padding-bottom: 50%;
overflow: hidden;
background-color: navy;
}
.item > a {
position: relative;
display: block;
overflow: hidden;
color: white;
}
.item:hover .grid-image:after {
background: rgba(0, 0, 0, .7);
}
.item:hover .grid-image > img {
-webkit-transform: scale(1.1);
-moz-transform: scale(1.1);
-ms-transform: scale(1.1);
-o-transform: scale(1.1);
transform: scale(1.1);
}
.item:hover .item-caption {
opacity: 1;
z-index: 3;
visibility: visible;
}
.item-caption,
.grid-image > img,
.grid-image:after {
-webkit-transition: all 0.3s ease-in-out 0s;
-moz-transition: all 0.3s ease-in-out 0s;
-ms-transition: all 0.3s ease-in-out 0s;
-o-transition: all 0.3s ease-in-out 0s;
transition: all 0.3s ease-in-out 0s;
}
.item-caption {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: rgba(29, 106, 154, 0.72);
color: #fff;
visibility: hidden;
text-align: center;
opacity: 0;
}
.grid-image {
position: relative;
overflow: hidden;
}
.grid-image img {
display: block;
overflow: hidden;
}
.grid-image:after {
position: absolute;
display: block;
content: "";
height: 100%;
width: 100%;
top: 0;
left: 0;
}
JavaScript
var $container = $('#page');
$container.masonry({
columnWidth: '.grid-sizer',
itemSelector: '.item',
percentPosition: true,
gutter: 10
});
Here's a fiddle
Thank you!

try this: http://jsfiddle.net/2stywe2t/1/
What I did:
Add a new div to your HTML, right under .item-caption.
Gave .item-caption the display: table attribute and a few others
Gave the new div display: table-cell, and vertical-align: middle
Removed position:relative from the a ancestor
Make sense?

Got the answer !! Just tidy up your code a bit.
var $container = $('#page');
$container.masonry({
columnWidth: '.grid-sizer',
itemSelector: '.item',
percentPosition: true,
gutter: 10
});
#page .item {
width: calc(16.66% - 10px);
display: inline-block;
height: 0;
float: left;
padding-bottom: 16.66%;
overflow: hidden;
background-color: salmon;
margin: 5px;
position: relative;
}
#page .item.s1 {
width: calc(50% - 10px);
padding-bottom: 50%;
overflow: hidden;
background-color: navy;
position: relative!important;
}
.item > a {
position: absolute;
display: block;
width: 100%;
height: 100%;
overflow: hidden;
color: white;
}
.item:hover .grid-image:after {
background: rgba(0, 0, 0, .7);
}
.item:hover .grid-image > img {
-webkit-transform: scale(1.1);
-moz-transform: scale(1.1);
-ms-transform: scale(1.1);
-o-transform: scale(1.1);
transform: scale(1.1);
}
.item:hover .item-caption {
opacity: 1;
z-index: 3;
visibility: visible;
}
.item-caption, .grid-image > img, .grid-image:after {
-webkit-transition: all 0.3s ease-in-out 0s;
-moz-transition: all 0.3s ease-in-out 0s;
-ms-transition: all 0.3s ease-in-out 0s;
-o-transition: all 0.3s ease-in-out 0s;
transition: all 0.3s ease-in-out 0s;
}
.item-caption {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: rgba(29, 106, 154, 0.72);
color: #fff;
visibility: hidden;
text-align: center;
opacity: 0;
display: table;
height: 100%;
width: 100%;
}
.grid-image {
position: relative;
overflow: hidden;
}
.grid-image img {
display: block;
overflow: hidden;
}
.grid-image:after {
position: absolute;
display: block;
content:"";
height: 100%;
width: 100%;
top: 0;
left: 0;
}
h5 {
display: table-cell;
vertical-align: middle;
}
<div class="container-fluid">
<div id="page">
<!-- GRID ITEM -->
<div class="item s1"> <a href="#">
<div class="grid-image">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/4/4e/Pleiades_large.jpg/1024px-Pleiades_large.jpg">
</div>
<div class="item-caption">
<h5>I want this to be center</h5>
</div>
</a>
</div>
<!-- /GRID ITEM -->
</div>
</div>
</body>
</html>

You simply need to add one line of code to your CSS to make this work:
h5 {
margin-top: 50%;
transform: translateY(-50%); /* not entirely necessary, but makes centering precise */
}
DEMO: http://jsfiddle.net/2stywe2t/4/

Related

How do you link an image to another page?

I have a div, and within it is an image that should work as a link to another page. There is some text laid over it. located here https://wearehomefolks.com/index.php/home/
I have taken this from somewhere else on the web, I may have modified it a little.
I just want the image to link out to the other internal pages. And keep the hover effect.
When I hover over the images of which there are 5, there is no linking action. What is going wrong here please?
<div class="hvrbox">
<a href="https://wearehomefolks.com/index.php/product-category/home-collection/">
<img src="https://wearehomefolks.com/wp-content/uploads/2021/07/Homefolks_Instruments_brass_edition_homefolks_homepage.jpg" alt="Mountains" class="hvrbox-layer_bottom">
</a>
<div class="hvrbox-layer_top">
<div class="hvrbox-text">HOME COLLECTION
</div>
</div>
</div>
css:
.hvrbox,
.hvrbox * {
box-sizing: border-box;
}
.hvrbox {
position: relative;
/*display: inline-block;*/
overflow: hidden;
max-width: 100%;
height: auto;
}
.hvrbox img {
max-width: 100%;
width:100%;
}
.hvrbox .hvrbox-layer_bottom {
display: block;
width: 100%;
}
.hvrbox .hvrbox-layer_top {
opacity: 0;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.4);
color: #fff;
/*padding: 15px;*/
-moz-transition: all 0.4s ease-in-out 0s;
-webkit-transition: all 0.4s ease-in-out 0s;
-ms-transition: all 0.4s ease-in-out 0s;
transition: all 0.4s ease-in-out 0s;
}
.hvrbox:hover .hvrbox-layer_top,
.hvrbox.active .hvrbox-layer_top {
opacity: 1;
}
.hvrbox .hvrbox-text {
text-align: center;
font-size: 4rem;
display: inline-block;
position: absolute;
line-height:4.5rem;
top: 50%;
left: 50%;
-moz-transform: translate(-50%, -50%);
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
.hvrbox .hvrbox-text_mobile {
font-size: 15px;
border-top: 1px solid rgb(179, 179, 179); /* for old browsers */
border-top: 1px solid rgba(179, 179, 179, 0.7);
margin-top: 5px;
padding-top: 2px;
display: none;
}
.hvrbox.active .hvrbox-text_mobile {
display: block;
}
Thanks
You should add pointer-events: none to the overlay (i.e. the CSS rule for .hvrbox .hvrbox-layer_top). That way the click can "go through it" to the linked image to trigger the link:
.hvrbox,
.hvrbox * {
box-sizing: border-box;
}
.hvrbox {
position: relative;
/*display: inline-block;*/
overflow: hidden;
max-width: 100%;
height: auto;
}
.hvrbox img {
max-width: 100%;
width:100%;
}
.hvrbox .hvrbox-layer_bottom {
display: block;
width: 100%;
}
.hvrbox .hvrbox-layer_top {
opacity: 0;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.4);
color: #fff;
/*padding: 15px;*/
-moz-transition: all 0.4s ease-in-out 0s;
-webkit-transition: all 0.4s ease-in-out 0s;
-ms-transition: all 0.4s ease-in-out 0s;
transition: all 0.4s ease-in-out 0s;
pointer-events:none;
}
.hvrbox:hover .hvrbox-layer_top,
.hvrbox.active .hvrbox-layer_top {
opacity: 1;
}
.hvrbox .hvrbox-text {
text-align: center;
font-size: 4rem;
display: inline-block;
position: absolute;
line-height:4.5rem;
top: 50%;
left: 50%;
-moz-transform: translate(-50%, -50%);
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
.hvrbox .hvrbox-text_mobile {
font-size: 15px;
border-top: 1px solid rgb(179, 179, 179); /* for old browsers */
border-top: 1px solid rgba(179, 179, 179, 0.7);
margin-top: 5px;
padding-top: 2px;
display: none;
}
.hvrbox.active .hvrbox-text_mobile {
display: block;
}
<div class="hvrbox">
<a href="https://wearehomefolks.com/index.php/product-category/home-collection/">
<img src="https://wearehomefolks.com/wp-content/uploads/2021/07/Homefolks_Instruments_brass_edition_homefolks_homepage.jpg" alt="Mountains" class="hvrbox-layer_bottom">
</a>
<div class="hvrbox-layer_top">
<div class="hvrbox-text">HOME COLLECTION
</div>
</div>
</div>

Remove specific hover effect from logo while keeping it a link back to homepage

I've search for an answer on the site without any luck. I have centered my logo in my header between my navigation links. I've added an underline hover effect to the links which also added the effect to my logo. I figured out how to remove the hover effect from the logo (pointer-event: none;) but this also keeps me from making the logo a clickable link back to my homepage. I tried placing my logo in a separate div thinking it would be easier to fix the issue but then I spent 3 hours trying to get things properly positioned (obviously, I'm new at web building). So now I've gone back to my original code hoping to get some assistance here. To summarize: How can I keep the hover effect on the nav links while removing it from the logo AND keeping the logo a clickable link to the hopepage? Thank you in advance for your help.
.header {
display: flex;
width: 100%;
margin-top: 0;
padding-top: 10px;
height: 20%;
align-items: center;
justify-content: center;
}
.cc_nav {
overflow: hidden;
position: fixed;
top: 0;
width: 100%;
background-color: white;
}
a {
text-decoration: none;
color: rgba(0, 0, 0, 0.8);
margin: 0 40px;
font-family: Tenar Sans;
font-size: .8em;
}
a {
-webkit-transform: translateZ(0);
transform: translateZ(0);
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
-moz-osx-font-smoothing: grayscale;
position: relative;
overflow: hidden;
}
a:before {
content: "";
position: absolute;
width: 100%;
height: 1px;
bottom: 0;
left: 0;
background-color: rgb(192, 192, 192);
visibility: hidden;
-webkit-transform: scaleX(0);
transform: scaleX(0);
-webkit-transition: all 0.3s ease-in-out 0s;
transition: all 0.3s ease-in-out 0s;
}
a:hover:before {
visibility: visible;
-webkit-transform: scaleX(1);
transform: scaleX(1);
}
#logo_Claire {
height: auto;
width: auto;
max-height: 140px;
max-width: 300px;
}
.noHover {
pointer-events: none;
}
<header>
<div class="cc_nav" id="centered_nav">
HOME
SERVICES
ABOUT
<img src="images/logo_2.png" alt="Claire Crawford" id="logo_Claire" />
PORTFOLIO
BLOG
GET IN TOUCH
</div>
</header>
Just add below CSS-
.noHover:hover::before {
background: none;
visibility: hidden;
}
and try below-working demo maybe it can help you.
.header {
display: flex;
width: 100%;
margin-top: 0;
padding-top: 10px;
height: 20%;
align-items: center;
justify-content: center;
}
.cc_nav {
overflow: hidden;
position: fixed;
top: 0;
width: 100%;
background-color: white;
}
a {
text-decoration: none;
color: rgba(0, 0, 0, 0.8);
margin: 0 40px;
font-family: Tenar Sans;
font-size: .8em;
}
a {
-webkit-transform: translateZ(0);
transform: translateZ(0);
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
-moz-osx-font-smoothing: grayscale;
position: relative;
overflow: hidden;
}
a:before {
content: "";
position: absolute;
width: 100%;
height: 1px;
bottom: 0;
left: 0;
background-color: rgb(192, 192, 192);
visibility: hidden;
-webkit-transform: scaleX(0);
transform: scaleX(0);
-webkit-transition: all 0.3s ease-in-out 0s;
transition: all 0.3s ease-in-out 0s;
}
a:hover:before {
visibility: visible;
-webkit-transform: scaleX(1);
transform: scaleX(1);
}
#logo_Claire {
height: auto;
width: auto;
max-height: 140px;
max-width: 300px;
}
.noHover:hover::before {
background: none;
visibility: hidden;
}
<header>
<div class="cc_nav" id="centered_nav">
HOME
SERVICES
ABOUT
<img src="images/logo_2.png" alt="Claire Crawford" id="logo_Claire" />
PORTFOLIO
BLOG
GET IN TOUCH
</div>
</header>
Just add css for not hovering on logo and clickable
a.noHover:hover:before {
visibility: visible;
-webkit-transform: scaleX(0);
transform: scaleX(0);
}
header{
display: flex;
width: 100%;
margin-top: 0;
padding-top: 10px;
height: 20%;
align-items: center;
justify-content: center;
}
.cc_nav {
overflow: hidden;
position: fixed;
top: 0;
width: 100%;
background-color: white;
}
a{
text-decoration: none;
color: rgba(0,0,0,0.8);
margin: 0 40px;
font-family: Tenar Sans;
font-size: .8em;
}
a {
-webkit-transform: translateZ(0);
transform: translateZ(0);
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
-moz-osx-font-smoothing: grayscale;
position: relative;
overflow: hidden;
}
a:before {
content: "";
position: absolute;
width: 100%;
height: 1px;
bottom: 0;
left: 0;
background-color: rgb(192,192,192);
visibility: hidden;
-webkit-transform: scaleX(0);
transform: scaleX(0);
-webkit-transition: all 0.3s ease-in-out 0s;
transition: all 0.3s ease-in-out 0s;
}
a:hover:before {
visibility: visible;
-webkit-transform: scaleX(1);
transform: scaleX(1);
}
a.noHover:hover:before {
visibility: visible;
-webkit-transform: scaleX(0);
transform: scaleX(0);
}
#logo_Claire {
height: auto;
width: auto;
max-height: 140px;
max-width: 300px;
}
<header>
<div class="cc_nav" id="centered_nav">
HOME
SERVICES
ABOUT
<img src="https://dummyimage.com/100x50/000/fff" alt="Claire Crawford" id="logo_Claire" />
PORTFOLIO
BLOG
GET IN TOUCH
<div>
</header>
you can try this, It is taking the default properties of anchor tag and you need to overwrite that so specify the important in your class properties
.noHover {
pointer-events: none !important;
}
Assign a class to the navigation links only and define your link and hover styles there.
<div class="cc_nav" id="centered_nav">
<a class="hover" href="">HOME</a>
<a class="hover" href="">SERVICES</a>
<a class="hover" href="">ABOUT</a>
<img src="images/logo_2.png" alt="Claire Crawford" id="logo_Claire" />
<a class="hover" href="">PORTFOLIO</a>
<a class="hover" href="">BLOG</a>
<a class="hover" href="">GET IN TOUCH</a>
<div>
CSS:
.cc_nav {
overflow: hidden;
position: fixed;
top: 0;
width: 100%;
background-color: white;
}
a {
text-decoration: none;
color: rgba(0, 0, 0, 0.8);
margin: 0 40px;
font-family: Tenar Sans;
font-size: 0.8em;
}
.hover {
-webkit-transform: translateZ(0);
transform: translateZ(0);
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
-moz-osx-font-smoothing: grayscale;
position: relative;
overflow: hidden;
}
.hover:before {
content: "";
position: absolute;
width: 100%;
height: 1px;
bottom: 0;
left: 0;
background-color: rgb(192, 192, 192);
visibility: hidden;
-webkit-transform: scaleX(0);
transform: scaleX(0);
-webkit-transition: all 0.3s ease-in-out 0s;
transition: all 0.3s ease-in-out 0s;
}
.hover:hover:before {
visibility: visible;
-webkit-transform: scaleX(1);
transform: scaleX(1);
}
#logo_Claire {
height: auto;
width: auto;
max-height: 140px;
max-width: 300px;
}
Here is a Pen

Slanted Div Hover Troubles

I've created a Slanted Div, however I ran into problem I cannot solve, I've googled this but did not find any answers.
body {
background: black;
}
#slantedwrapper {
overflow: hidden;
margin-left: 50px;
}
#slanted {
display: inline-block;
/* margin-right:-4px; */
width: 400px;
margin-left: -45px;
/* background-image: url("http://www.keenthemes.com/preview/conquer/assets/plugins/jcrop/demos/demo_files/image2.jpg"); */
}
#slanted a {
position: relative;
background-color: #1d1d1d;
/* background-image: url("http://www.keenthemes.com/preview/conquer/assets/plugins/jcrop/demos/demo_files/image2.jpg"); */
box-sizing: border-box;
background-size: cover;
/* padding:1em; */
display: block;
transform: skewX(-30deg);
width: 100%;
min-height: 3.5em;
text-align: center;
border-right: 5px solid #20c397;
height: 150px;
/* line-height: 110px; */
overflow: hidden;
}
#slanted span {
color: white;
position: absolute;
box-sizing: border-box;
transform: skewX(30deg);
left: 0;
width: 100%;
/* height: 150px; */
/* background-image: url("http://www.keenthemes.com/preview/conquer/assets/plugins/jcrop/demos/demo_files/image2.jpg"); */
}
}
}
.current a {
background:#70cb00;
}
#slanted a img {
transform: skewX(30deg);
overflow: hidden;
margin-top: -20px;
padding-top: 0px;
width: 123%;
height: 123%;
margin-left: -50px;
opacity: 0.6;
-webkit-transition: opacity 0.3s linear 0s;
-o-transition: opacity 0.3s linear 0s;
transition: opacity 0.3s linear 0s;
}
#slanted img:hover {
opacity:1;
}
#caption {
background-color: #333333;
width: 100%;
height: 25px;
display: block;
position: absolute;
bottom: 0;
z-index: 99;
opacity: 0.7;
color: #D2D2D2;
-webkit-transition: background-color 0.3s linear 0s;
-o-transition: background-color 0.3s linear 0s;
transition: background-color 0.3s linear 0s;
}
/*Combination hover effects*/
#slanted:hover #caption {
background-color: #20c397;
opacity:1.0;
}
#slanted:hover img {
opacity:1.0;
}
/* END OFCombo hover effects*/
p.nonskew {
transform: skewX(30deg);
color: White;
margin: 0;
margin-left: 22%;
padding: 1.5%;
text-align: left;
font-size: 0.8em;
}
<div id="slantedwrapper">
<div id="slanted">
<a href="#">
<div id="caption">
<p class="nonskew">A Caption: Description</p>
</div>
<img src="http://www.keenthemes.com/preview/conquer/assets/plugins/jcrop/demos/demo_files/image2.jpg" alt="SLANTED DIV"></a>
</div>
<!--end of wrapper-->
</div>
JSFiddle version
here's the problem:
Hover over the div, it hovers fine, but at the bottom right corner, where nothing is there (where the overflow is hidden) still hovers if you place your mouse over the blank area where the angle begins, how do I solve this into when it hovers- it only applies to shape of the div only?
Thank you
You seem to have the right idea, using both the unskew and intuitive to using the skew, however, something like the below example may work for you:
html {
background: radial-gradient(#222, blue);
height: 100%;
}
div.wrap{
height: 150px;
width: 300px; position: relative;
overflow: hidden;
}
div.innerwrap {
height: 100%;
width: 100%;
transform: skewX(-30deg);
position: absolute;top:0;left:0;
overflow: hidden;
margin-left: -70px;
transition: all 0.4s;
border-right: 5px solid tomato;
cursor:pointer;
}
div.innerwrap:hover span {
background: gold;
}
div.innerwrap:before {
content: "";
position: absolute;
top: 0;
right: 0;
width: 100%;
height: 100%;
background: url(http://lorempixel.com/300/300);
transform: skewX(30deg);
transform-origin: top left;
}
div span {
position: absolute;
bottom: 0;
left: 0%;
width: 120%;
transform: skewX(30deg);
background: red;
text-align:center;
transition: all 0.4s;
}
<div class="wrap">
<div class="innerwrap">
<span>TITLE</span>
</div>
</div>
For further information, #Harry has created a wide variety of examples here in which you may find useful.

Make Image overlay clickable to link to another page

jsfiddle: https://jsfiddle.net/e0u4sow1/
I want to use the following code for an image to link to another page. Right now if I make it a link it doesn't work. I read somewhere I need to add
pointer-events: none;
somewhere in the code. It tried, but it either doesn't work or it works but removes the overlay.
HTML:
<h1>MR Cube</h1>
<div class="media"></div>
<div class="media"><img alt="" class="media__image" src="http://www.webwinkelsucces.nl/wp-content/uploads/2015/05/1112625-les-outils-de-test-et-d-integration-continue-open-source.jpg" />
<div class="media__body">
<h1>Lees meer</h1>
</div>
</div>
CSS:
.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; }
move .media__body inside a
<a href="http://www.google.nl/">
<img alt="" class="media__image" src="http://www.webwinkelsucces.nl/wp-content/uploads/2015/05/1112625-les-outils-de-test-et-d-integration-continue-open-source.jpg" />
<div class="media__body">
<h1>Lees meer</h1>
</div>
</a>
check this fiddle
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.image-container{
width:200px;
position:relative;
overflow: hidden;
}
.image-container img {
max-width: 100%;
height: auto;
display: block; /* added this */
}
.image-container a {
position:absolute;
color: #fff;
width: 100%;
height: 100%;
top: 0;
left: 0;
padding: 0;
z-index:2;
}
.image-container .image-overlay{
opacity:0;
position:absolute;
color: #fff;
background: rgba(141, 178, 215, 0.77);
width: 100%;
height: 100%;
top: 0;
left: 0;
padding: 0;
text-align:center;
font-size:40px;
line-height: 200px; /* added this */
-webkit-transition: opacity .5s ease-in-out;
-moz-transition: opacity .5s ease-in-out;
-ms-transition: opacity .5s ease-in-out;
-o-transition: opacity .5s ease-in-out;
transition: opacity .5s ease-in-out;
z-index:1;
}
.image-container:hover .image-overlay{
opacity:1;
}
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
<div class="image-container">
<div class="image-overlay">
<i class="fa fa-search"></i>
</div>
<img src="https://placehold.it/350x350">
</div>
Although JQuery has not been tagged, this is what you could have done using it:
$(".media__body").click(function(){
window.location = "http://www.google.com/";
});
Here is a Demo
Here is the solution, just wrap all tags used for image with <a> tag
Demo
<h1>MR Cube</h1>
<a href="www.google.com" >
<div class="media"></div>
<div class="media"><img alt="" class="media__image" src="http://www.webwinkelsucces.nl/wp-content/uploads/2015/05/1112625-les-outils-de-test-et-d-integration-continue-open-source.jpg" />
<div class="media__body">
<h1>Lees meer</h1>
</div>
</div>
</a>

Vertically center text on an image - dynamically

I have images and a text that is displayed in the center of the image when somebody is hovering over the image.
HTML looks like this:
<article>
<div class="entry-content">
<a href="http://www.linktopost.com">
<h3 class="entry-title">Ring #1</h3>
<img width="620" height="387" src="http://i.telegraph.co.uk/multimedia/archive/02725/scotch-whisky_2725818b.jpg" class="aligncenter" alt="Platzhalter_3">
</a>
</div>
</article>
CSS:
article {
float:left;
width:30%;
display:block;
}
.entry-content {
width: 620px;
margin: 0 auto;
position: relative;
height: 387px;
}
.entry-content:hover .entry-title {
color: #000;
display: table-cell;
background-color: #fff;
opacity: 0.75;
}
.entry-title {
position: absolute;
width: 100%;
height: 100%;
z-index: 9999;
line-height: 387px;
text-align: center;
display: none;
}
article img {
position:absolute;
}
You can see it here:
http://codepen.io/anon/pen/rOXOez
Is there any chance to not use fixed pixel values in the CSS - so that the hover effect is valid and working for any picture? In this example I had to use the width and height of the picture in the CSS to achieve what I wanted.
Thank you!
Solution 1:
Relative/Absolute positioning and center with transform: translate()
https://jsfiddle.net/94efk8kz/
article {
position: relative;
}
.hover-content {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: white;
color: black;
opacity: 0;
-webkit-transition: all 0.3s ease-in-out;
-moz-transition: all 0.3s ease-in-out;
-o-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
}
.hover-content h3 {
position: absolute;
top: 50%;
left: 50%;
margin: 0;
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
-o-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
Solution 2:
Flexbox
https://jsfiddle.net/94efk8kz/1/
article {
position: relative;
}
img {
width: 100%;
}
.hover-content {
width: 100%;
height: 100%;
top: 0;
display: flex;
position: absolute;
align-items: center;
justify-content: center;
background: white;
color: black;
opacity: 0;
-webkit-transition: all 0.3s ease-in-out;
-moz-transition: all 0.3s ease-in-out;
-o-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
}
Solution 3
CSS Tables
https://jsfiddle.net/94efk8kz/2/
.entry-content a {
float: left;
width:30%;
position: relative;
height: 100%;
}
.hover-content {
width: 100%;
height: 100%;
top: 0;
left: 0;
position: absolute;
background: white;
color: black;
opacity: 0;
bottom: 0;
right: 0;
-webkit-transition: all 0.3s ease-in-out;
-moz-transition: all 0.3s ease-in-out;
-o-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
}
.v-align {
display: table;
height: 100%;
margin: 0 auto;
}
.hover-content h3 {
display: table-cell;
vertical-align: middle;
}
Try with these changes
.entry-content {
width: initial;
}
.entry-content:hover .entry-title {
margin: 0;
}
.article img {
display: block;
/* position: absolute; remove this,avoid using positon absolute where you can */
width: 100%;
}