How to have 2 hover effects work at the same time? - html

So I'm a little stuck with the hover effects I'm trying to make 2 hover effects work at the same time. My goal is to have a frosted glass effect with text overlay. Here is my codepen https://codepen.io/kyannashanice/pen/mdRjmry
Stylesheet:
.product {
width: 400px;
height: 400px;
}
.container {
position: relative;
width: 400px;
height: 400px;
}
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
height: 100%;
width: 100%;
opacity: 0;
transition: .5s ease;
z-index: 99;
}
.container:hover .overlay {
opacity: 1;
}
.text {
color: white;
font-size: 30px;
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
text-align: center;
}
/* Blur Hover Effect */
img {
position: absolute;
filter: none;
-moz-transition: all 0.4s ease-out;
-webkit-transition: all 0.4s ease-out;
-ms-transition: all 0.4s ease-out;
-o-transition: all 0.4s ease-out;
transition: all 0.4s ease-out;
border-radius:5px;
border:1px solid black;
}
img:hover {
opacity: 0.8;
filter: -webkit-filter: blur(4px);
filter: blur(4px);
-moz-transition: all 0.4s ease-out;
-webkit-transition: all 0.4s ease-out;
-ms-transition: all 0.4s ease-out;
-o-transition: all 0.4s ease-out;
transition: all 0.4s ease-out;
}
HTML:
<p>Both hover effects applied but one working over the other</p>
<div class="container">
<img src="https://www.mydomaine.com/thmb/aA3TdLIHHviKBrIBVLExBBnQjSA=/1790x1790/filters:no_upscale():max_bytes(150000):strip_icc():format(webp)/string-of-pearls-product2-2f5350b5894642ea8942a2726ee20f13.jpg" class="product">
<div class="overlay">
<div class="text">Hello World</div>
</div>
</div>
<br>
<br>
<br>
<p>No text overlay</p>
<img src="https://www.mydomaine.com/thmb/aA3TdLIHHviKBrIBVLExBBnQjSA=/1790x1790/filters:no_upscale():max_bytes(150000):strip_icc():format(webp)/string-of-pearls-product2-2f5350b5894642ea8942a2726ee20f13.jpg" class="product">
Both overlays work fine on their own but when they overlap only the text overlay will show. I would appreciate any help or direction if anyone knows how to make both effects go off at the same time.
Thank you!

The problem is that the hover is set to img. First you get the .overlay class that covers the photo and therefore the hover in the photo does not work.
Try add hover to container: ( instead img:hover)
.container:hover img{
opacity: 0.8;
filter: -webkit-filter: blur(4px);
filter: blur(4px);
-moz-transition: all 0.4s ease-out;
-webkit-transition: all 0.4s ease-out;
-ms-transition: all 0.4s ease-out;
-o-transition: all 0.4s ease-out;
transition: all 0.4s ease-out;
}
Markup HTML
Photo with text
<div class="container">
<img src="" class="product">
<div class="overlay">
<div class="text">Hello World</div>
</div>
</div>
Photo without text
<div class="container">
<img src="" class="product">
</div>

Related

css dynamically overlaid <divs> with mouse-over opacity

We are trying to get our new company-team page up and running. What we are trying to accomplish is to have employee images in <divs> so they resize dynamically, and then on mouse over have the image dimmed and the employee bio visible. Something similar to the employee mouseover found here: http://studiompls.com/about/
What has been cobbled together that sort of works:
<!DOCTYPE html>
<html>
<head>
<style>
div.gallery {
position:relative;
background: #6E6E6E;
color: #fff;
font-weight:bold;
top:0;
left:0;
opacity: 1;
-webkit-transition: opacity .25s ease-in-out;
-moz-transition: opacity .25s ease-in-out;
-ms-transition: opacity .25s ease-in-out;
-o-transition: opacity .25s ease-in-out;
transition: opacity .25s ease-in-out;
}
div.gallery:hover {
opacity: .6;
-webkit-transition: opacity .25s ease-in-out;
-moz-transition: opacity .25s ease-in-out;
-ms-transition: opacity .25s ease-in-out;
-o-transition: opacity .25s ease-in-out;
transition: opacity .25s ease-in-out;
}
div.gallery img {
width: 100%;
height: auto;
}
div.desc {
position: relative;
top: 50%;
transform: translateY(-50%);
vertical-align:middle;
}
* {
box-sizing: border-box;
}
.responsive {
padding: 0 6px;
float: left;
width: 24.99999%;
vertical-align:middle;
position:relative;
}
.responsive:hover{
}
#media only screen and (max-width: 700px) {
.responsive {
width: 49.99999%;
margin: 6px 0;
}
}
#media only screen and (max-width: 500px) {
.responsive {
width: 100%;
}
}
.clearfix:after {
content: "";
display: table;
clear: both;
}
.wrapper{
position:relative;
background: #6E6E6E;
color: #fff;
font-weight:bold;
top:0;
left:0;
opacity: 1;
-webkit-transition: opacity .25s ease-in-out;
-moz-transition: opacity .25s ease-in-out;
-ms-transition: opacity .25s ease-in-out;
-o-transition: opacity .25s ease-in-out;
transition: opacity .25s ease-in-out;
}
.wrapper:hover{
opacity: .6;
-webkit-transition: opacity .25s ease-in-out;
-moz-transition: opacity .25s ease-in-out;
-ms-transition: opacity .25s ease-in-out;
-o-transition: opacity .25s ease-in-out;
transition: opacity .25s ease-in-out;
}
</style>
</head>
<body>
<div class="responsive">
<div class="wrapper">
<div class="gallery">
<img src="images/Gary.jpeg" alt="" width="300" height="200">
</div>
</div>
</div>
<div class="responsive">
<div class="wrapper">
<div class="gallery">
<img src="images/Andy.jpeg" alt="" width="300" height="200">
</div>
</div>
</div>
<div class="responsive">
<div class="wrapper">
<div class="gallery">
<img src="images/Chris.jpg" alt="" width="300" height="200">
</div>
</div>
</div>
<div class="clearfix"></div>
<div class="responsive">
<div class="wrapper">
<div class="gallery">
<div class="clearfix"></div>
<div style="padding:6px;">
</div>
</body>
</html>
The overlaid <div>s do no stay lined up, and if we add text to the background <div> it separates them further. Anyone see what's missing here?
Try this HTML and CSS
Extra CSS
.container {
position: relative;
}
.image {
opacity: 1;
display: block;
width: 100%;
height: auto;
transition: .5s ease;
backface-visibility: hidden;
}
.middle {
transition: .5s ease;
opacity: 0;
position: absolute;
top: 50%;
left: 50%;
height: 100%;
width: 100%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
text-align: center;
}
.container:hover .image {
opacity: 0.3;
}
.container:hover .middle {
opacity: 1;
background-color: black;
}
.text {
color: white;
font-size: 16px;
padding: 16px 32px;
}
UPdated HTML
<div class="gallery container">
<img class="image" src="https://www.w3schools.com/howto/img_avatar.png" width="300" height="200">
<div class="middle">
<div class="text">John Doe</div>
</div>
</div>
https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_image_overlay_opacity
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.container1 {
display: flex;
flex-wrap: wrap;
}
div.gallery {
position:relative;
background: #6E6E6E;
color: #fff;
font-weight:bold;
top:0;
left:0;
opacity: 1;
-webkit-transition: opacity .25s ease-in-out;
-moz-transition: opacity .25s ease-in-out;
-ms-transition: opacity .25s ease-in-out;
-o-transition: opacity .25s ease-in-out;
transition: opacity .25s ease-in-out;
}
div.gallery:hover {
-webkit-transition: opacity .25s ease-in-out;
-moz-transition: opacity .25s ease-in-out;
-ms-transition: opacity .25s ease-in-out;
-o-transition: opacity .25s ease-in-out;
transition: opacity .25s ease-in-out;
}
div.gallery img {
width: 100%;
height: auto;
}
div.desc {
position: relative;
top: 50%;
transform: translateY(-50%);
vertical-align:middle;
}
* {
box-sizing: border-box;
}
.responsive {
padding: 0 6px;
width:33.3%;;
vertical-align:middle;
position:relative;
}
#media only screen and (max-width: 700px) {
.responsive {
width: 49.9%;
margin: 6px 0;
}
}
#media only screen and (max-width: 500px) {
.responsive {
width: 100%;
}
}
.clearfix:after {
content: "";
display: table;
clear: both;
}
.wrapper{
position:relative;
background: #6E6E6E;
color: #fff;
font-weight:bold;
top:0;
left:0;
opacity: 1;
-webkit-transition: opacity .25s ease-in-out;
-moz-transition: opacity .25s ease-in-out;
-ms-transition: opacity .25s ease-in-out;
-o-transition: opacity .25s ease-in-out;
transition: opacity .25s ease-in-out;
}
.wrapper:hover{
-webkit-transition: opacity .25s ease-in-out;
-moz-transition: opacity .25s ease-in-out;
-ms-transition: opacity .25s ease-in-out;
-o-transition: opacity .25s ease-in-out;
transition: opacity .25s ease-in-out;
}
.container {
position: relative;
}
.image {
opacity: 1;
display: block;
width: 100%;
height: auto;
transition: .5s ease;
backface-visibility: hidden;
}
.middle {
transition: .5s ease;
opacity: 0;
position: absolute;
top: 50%;
left: 50%;
height: 100%;
width: 100%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
text-align: center;
}
.container:hover .image {
opacity: 0.3;
}
.container:hover .middle {
opacity: 1;
background-color: black;
}
.text {
color: white;
font-size: 16px;
padding: 16px 32px;
}
</style>
</head>
<body>
<body>
<div class="container1">
<div class="responsive">
<div class="wrapper">
<div class="gallery container">
<img class="image" src="https://www.w3schools.com/howto/img_avatar.png" width="300" height="200">
<div class="middle">
<div class="text">John Doe</div>
</div>
</div>
</div>
</div>
<div class="responsive">
<div class="wrapper">
<div class="gallery container">
<img class="image" src="https://www.w3schools.com/howto/img_avatar.png" width="300" height="200">
<div class="middle">
<div class="text">John Doe</div>
</div>
</div>
</div>
</div>
<div class="responsive">
<div class="wrapper">
<div class="gallery container">
<img class="image" src="https://www.w3schools.com/howto/img_avatar.png" width="300" height="200">
<div class="middle">
<div class="text">John Doe</div>
</div>
</div>
</div>
</div>
<div class="clearfix"></div>
<div class="responsive">
<div class="wrapper">
<div class="gallery">
<div class="clearfix"></div>
<div style="padding:6px;"></div>
</div>
</body>
</html>

Css Transform: Scale Only Works in Dev Tools

I'm trying to achieve a simple :hover effect where the image hovered scales up when hovered. Strangely, when I click the :hover radio button in the "Force element state" in Chrome dev tools, the effect works as expected, but when I actually hover over the image, no dice. Any insight would be much appreciated!
This is my markup (the image has a semi opaque overlay)
<article class="news-loop_item">
<img
src="http://imgsv.imaging.nikon.com/lineup/lens/zoom/normalzoom/af-
s_dx_18-300mmf_35-56g_ed_vr/img/sample/sample4_l.jpg" class="news-
loop_img" alt="featured image">
<div class="news-loop_overlay">
<h2 class="news-loop_title">Title</h2>
<p class="news-loop_date">Date</p>
<div class="news-loop_summary">Summary</div>
</div>
</article>
And my scss
.news-loop {
flex-wrap: wrap;
margin: -1rem;
}
.news-loop_item {
flex-basis: calc(100% / 2 - 2rem);
height: 20rem;
margin: 1rem;
overflow: hidden;
position: relative;
}
.news-loop_img {
height: 100%;
object-fit: cover;
overflow: hidden;
-webkit-transition: all .3s ease-in-out;
-moz-transition: all .3s ease-in-out;
-ms-transition: all .3s ease-in-out;
-o-transition: all .3s ease-in-out;
transition: all .3s ease-in-out;
position: relative;
vertical-align: middle;
width: 100%;
}
.news-loop_img:hover {
-webkit-transform: scale(1.15, 1.15);
transform: scale(1.15, 1.15);
}
.news-loop_overlay {
background: rgba(0, 0, 0, .75);
height: 100%;
left: 0;
position: absolute;
top: 0;
width: 100%;
-webkit-transition: all .3s ease-in-out;
-moz-transition: all .3s ease-in-out;
-ms-transition: all .3s ease-in-out;
-o-transition: all .3s ease-in-out;
transition: all .3s ease-in-out;
}
.news-loop_overlay:hover {
background: rgba(0, 0, 0, .5);
}
https://codepen.io/evanhickman/pen/ZXOmWb
The reason why is that your hover selector is wrong, check out this:
.news-loop_item:hover .news-loop_img {
-webkit-transform: scale(1.15, 1.15);
transform: scale(1.15, 1.15);
}
See the parent element needs the hover event.
The issue is because your .news-loop_overlay class div is 'capturing' the hover effect.
Try adding a z-index: -1; to that div and you'll see that the scale works.

p tag inside of a div tag

This is a two part problem. The first part is I want the image fade and the text fade to happen at the same time (on a hover over).
The second part is, I thought if I had the <p> tag inside of the <div> then it would "inherit" (I may not be using the term properly) the div properties. The text is supposed to remain fixed center of the image so anytime the image resizes or moves it takes the text with it.
Clearly neither one of those things are happening.
.image-wrapper p {
position: absolute;
left: 250px;
top: 130px;
padding: 10px;
border: 1px solid #FFF;
opacity: 0;
}
.image-wrapper p:hover {
position: absolute;
left: 250px;
top: 130px;
padding: 10px;
border: 1px solid #FFF;
opacity: 100;
transition: opacity .25s ease-in-out;
-moz-transition: opacity .25s ease-in-out;
-webkit-transition: opacity .25s ease-in-out;
}
.fade {
opacity: 1;
transition: opacity .25s ease-in-out;
-moz-transition: opacity .25s ease-in-out;
-webkit-transition: opacity .25s ease-in-out;
}
.fade:hover {
opacity: 0.5;
}
<div class="image-wrapper">
<img src="http://placehold.it/150x80?text=IMAGE" class="fade" style="width:100%" alt="Image">
<p>This text here</p>
</div>
Here is a link just in case
Check this out and let me know your feedback. Thanks!
The first part is I want the image fade and the text fade to happen at the same time (on a hover over).
For this to happen, add hover to image-wrapper rather than individually to p and the img like the below for instance:
.image-wrapper:hover p {
opacity: 1;
}
.image-wrapper:hover .fade {
opacity: 0.5;
}
The text is supposed to remain fixed center of the image so anytime
the image resizes or moves it takes the text with it.
For this you can use the transform to center align the text over the image responsively.
.image-wrapper p {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
snippet below:
.image-wrapper{
position: relative;
}
.image-wrapper p {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
padding: 10px;
border: 1px solid #FFF;
opacity: 0;
transition: opacity .25s ease-in-out;
-moz-transition: opacity .25s ease-in-out;
-webkit-transition: opacity .25s ease-in-out;
}
.image-wrapper:hover p {
opacity: 1;
}
.fade {
opacity: 1;
transition: opacity .25s ease-in-out;
-moz-transition: opacity .25s ease-in-out;
-webkit-transition: opacity .25s ease-in-out;
}
.image-wrapper:hover .fade {
opacity: 0.5;
}
<div class="image-wrapper">
<img src="http://placehold.it/150x80?text=IMAGE" class="fade" style="width:100%" alt="Image">
<p>This text here</p>
</div>
for first one you can use like that
.image-wrapper:hover{
opacity :0.7;
}
Both 1.) and 2.) - Try this code:
HTML:
<div class="image-wrapper">
<img src="http://placehold.it/150x80?text=IMAGE" class="fade" style="width:100%" alt="Image">
<p class="fade">This text here</p>
</div>
Adding the class="fade" to the <p> will make the transition smoothly for the text as well.
CSS:
.image-wrapper p {
display: none;
color: #F00;
position: absolute;
left: 250px;
top: 130px;
padding: 10px;
border: 1px solid #FFF;
opacity: 0;
}
.image-wrapper p:hover, .image-wrapper:hover p {
display: block;
position: absolute;
left: 250px;
top: 130px;
padding: 10px;
border: 1px solid #FFF;
opacity: 100;
transition: opacity .25s ease-in-out;
-moz-transition: opacity .25s ease-in-out;
-webkit-transition: opacity .25s ease-in-out;
}
// When either hovering the p or the image, apply the transition.
.fade {
opacity: 1;
transition: opacity .25s ease-in-out;
-moz-transition: opacity .25s ease-in-out;
-webkit-transition: opacity .25s ease-in-out;
}
.fade:hover {
opacity: 0.5;
}

html img default+hover+onclick

im pretty new at coding and im struggling right now.
I currently have image with text appearing when i hover it. Using overlay + opacity.
What I would like to have:
img = this picture
img hover = this picture
img on click = the text with the orange background wich i currently have on hover.
Thanks for the help and sorry for my english.
EDIT: here is the code.
EDIT2: i would like to make it look like this but with text as onclick, not a picture. Basically the same looking text as i have currently got on hover:
img src="image1" alt="image"
onmouseover="this.src='image2';"
onclick="this.src='image3';
onmouseout="this.src='image1';"
.item .item-wrap {
overflow: hidden;
position: relative;
}
.item .item-wrap a {
display: block;
cursor: pointer;
}
.item .item-wrap .overlay {
background: #ed560e;
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
filter: alpha(opacity=0);
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
opacity: 0;
zoom: 1;
-moz-transition: opacity 0.3s ease-in-out;
-o-transition: opacity 0.3s ease-in-out;
-webkit-transition: opacity 0.3s ease-in-out;
-ms-transition: opacity 0.3s ease-in-out;
transition: opacity 0.3s ease-in-out;
}
.item .item-wrap img {
vertical-align: bottom;
-moz-transition: all 0.3s ease-in-out;
-o-transition: all 0.3s ease-in-out;
-webkit-transition: all 0.3s ease-in-out;
-ms-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
}
.item .item-wrap .bieres-item-meta {
position: absolute;
top: 10%;
left: 10%;
filter: alpha(opacity=0);
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
opacity: 0;
zoom: 1;
-moz-transition: opacity 0.3s ease-in-out;
-o-transition: opacity 0.3s ease-in-out;
-webkit-transition: opacity 0.3s ease-in-out;
-ms-transition: opacity 0.3s ease-in-out;
transition: opacity 0.3s ease-in-out;
}
.item .item-wrap .bieres-item-meta h5 {
font: 15px/21px"raleway-heavy", sans-serif;
margin: 0;
color: white;
word-wrap: break-word;
}
.item .item-wrap .bieres-item-meta p {
font: 14px/18px"raleway-semibold", sans-serif;
color: #fbcab3;
margin: 0;
}
/* on item hover */
.item:hover .overlay {
filter: alpha(opacity=100);
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";
opacity: 1;
zoom: 1;
}
.item:hover .bieres-item-meta {
filter: alpha(opacity=100);
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";
opacity: 1;
zoom: 1;
}
.item:hover .item-wrap img {
-moz-transform: scale(1.2);
-o-transform: scale(1.2);
-webkit-transform: scale(1.2);
-ms-transform: scale(1.2);
transform: scale(1.2);
}
<div class="bgrid item">
<div class="item-wrap">
<a href="#">
<img src="http://v5.lapiece.ch/images/portfolio/mobykid.jpg" alt="Moby Kid">
</a>
<div class="overlay"></div>
<div class="bieres-item-meta">
<h5>Moby Kid</h5>
</br>
<p style="margin-right: 20px;">
Apparence: Robe jaune pâle et trouble. Bonne tenue de mousse.</br>
</br>
Arôme: Fruité avec des notes de banane.</br>
</br>
Goût: Légèrement acidulé, avec des saveurs nets d'agrumes et discrètes de fruits tropicaux.
</br>
</br>
Alcool: 4.5 [ % ]</br>
Couleur: 6 [ EBC ]</br>
Amertume: 18 [ IBU ]</br>
Densité finale: 1009 [ g/l ]</p>
</div>
</div>
</div>
You may use something like this - For hovering effect
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
.imgBox
{
width: 441px;
height: 248px;
background: url(img1.jpg) no-repeat;
}
.imgBox:hover
{
background: url(img2.jpg) no-repeat;
<!--These are optional-->
-moz-box-shadow: 0 0 10px #ccc;
-webkit-box-shadow: 0 0 10px #ccc;
box-shadow: 0 0 10px #ccc;
}
</style>
</head>
<body>
<div class="imgBox">
</div>
</body>
</html>
Just put an image in the background of your overlay class
background-image: url('something.jpg');

How to align vertically text on :hover

The vertical alignment of the text on :hover isn't working . Also after hovering, the whole area of posts should be cover with pointer cursor and should be clickable, but it isn't.
HTML
<div class="photoset post-background">
<div class="imgoverlay text-light">
<a href="{Permalink}">
<div class="photos">
{block:Photos}
<img alt="" src="{PhotoURL-500}">
{/block:Photos}
</div>
<div class="overlay">
<span class="overlaycolor"></span>
<div class="overlayinfo">
{block:ContentSource}
<h6>{SourceTitle}</h6>
{block:ContentSource}
</div>
</div>
</a>
</div>
</div>
CSS
.imgoverlay {
position: relative;
overflow: hidden;
display: block;
max-width: 100%;
}
.imgoverlay img {
-webkit-transition: all .4s ease;
-moz-transition: all .4s ease;
-o-transition: all .4s ease;
-ms-transition: all .4s ease;
transition: all .4s ease;
}
.imgoverlay .overlay {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
z-index: 0;
opacity: 0;
filter: alpha(opacity=0);
-ms-filter: "alpha(Opacity=0)";
-webkit-transition: opacity .3s ease;
-moz-transition: opacity .3s ease;
-o-transition: opacity .3s ease;
-ms-transition: opacity .3s ease;
transition: opacity .3s ease;
}
.imgoverlay:hover .overlay {
opacity: 1;
filter: alpha(opacity=100);
-ms-filter: "alpha(Opacity=100)";
}
.imgoverlay .overlaycolor {
width: 100%;
height: 100%;
background: {color:Post Hover};
};
Example http://www.jnck.sk/
Thanks for any help!
Use span with display:block instead of div inside link. Block elements like div shouldn't be in inline blocks.
For vertical align of text you can use i.e. this:
.overlayinfo {
position: relative;
top: 50%;
transform: translateY(-50%);
}
http://zerosixthree.se/vertical-align-anything-with-just-3-lines-of-css/