Hover effect on background image - css

I've added a black transparency to appear when they hover on a background image on my site. I have a h2 tag which also appears on the hover but sits behind the dark transparency where as I want it on top of it! Is there a solution to this?
<div class="img-option">
<div class="content">
<h2>example<\h2>
<\div>
<\div>
CSS:
.img-option
Background image Position relative Background repeat no repeat Background Size cover .img-option:hover Filter: brightness (.6)
Thanks

.img-option {
background-image: url(https://static.vecteezy.com/system/resources/previews/000/106/719/original/vector-abstract-blue-wave-background.jpg);
position: absolute;
height: 200px;
width: 400px;
}
.img-option:after,
h2:before {
position: absolute;
transition: all 0.2s;
-webkit-transition: all 0.2s;
}
.img-option:after {
content: '';
opacity: 0;
top: 0;
left: 0;
background-color: rgba(0, 0, 0, 0.1);
width: 100%;
height: 100%;
}
h2:before {
content: attr(data-content);
top: 60%;
z-index: 1;
box-sizing: border-box;
-moz-box-sizing: border-box;
padding: 2% 3%;
border: solid #000000 1px;
background-color: #ffffff;
}
.img-option:hover:after {
opacity: 1;
}
<div class="img-option">
<div class="content">
<h2 data-content="example"></h2>
</div>
</div>

You would need to assign a z-index to your <h2> element.
z-index: 1;
You can find out more about the the z-index property here.

add .img-option:before element and add style position:absolute and adjust the height like below.
DEMO:-
.img-option {
overflow: hidden;
}
.img-option h2 {
margin: 0;
padding: 20px;
}
.img-option:before {
content: '\00a0';
font-size: 1.5em;
width: 100%;
z-index: 100;
padding: 20px;
overflow: hidden;
position: absolute;
opacity: 0;
overflow: visible;
box-sizing: border-box;
transition: all 0.4s ease-in-out;
position: absolute;
}
.img-option:hover:before {
opacity: 1;
background-color: rgba(0, 0, 0, 0.7);
}
<div class="img-option">
<div class="content">
<h2>example</h2>
</div>
</div>

Related

Adding Blur Effect On Image

For adding blur effect on image, I create another element from the same image with absolute position, low opacity and blur effect. I don't think this is efficient. What's the best approach for this situation?
<img src="./images/shopping.svg" />
<img style="position: absolute;opacity: 0.5;filter: blur(10px);" src="./images/shopping.svg" />
Preview
You can use drop-shadow filter, to achieve the desired effect. This also kills the need of using second img tag.
body{
background: #222;
}
img{
filter: drop-shadow(0 0 10px rgba(0, 0, 0, 0.5)) invert(100%);
/* Note - I used invert(100%) to invert the colors since the original svg was black.
If you want to remove it, you need to use rgba(255, 255, 255, 0.5) for white
shadow.
*/
}
<img src="https://www.svgrepo.com/show/80543/shopping-cart-outline.svg" width="300" />
blur hover effect using like this may be it's helping us:
.column {
margin: 15px 15px 0;
padding: 0;
}
.column:last-child {
padding-bottom: 60px;
}
.column::after {
content: '';
clear: both;
display: block;
}
.column div {
position: relative;
float: left;
width: 300px;
height: 200px;
margin: 0 0 0 25px;
padding: 0;
}
.column div:first-child {
margin-left: 0;
}
.column div span {
position: absolute;
bottom: -20px;
left: 0;
z-index: -1;
display: block;
width: 300px;
margin: 0;
padding: 0;
color: #444;
font-size: 18px;
text-decoration: none;
text-align: center;
-webkit-transition: .3s ease-in-out;
transition: .3s ease-in-out;
opacity: 0;
}
figure {
width: 300px;
height: 200px;
margin: 0;
padding: 0;
background: #fff;
overflow: hidden;
}
figure:hover+span {
bottom: -36px;
opacity: 1;
}
/* Blur */
.hover07 figure img {
-webkit-filter: blur(3px);
filter: blur(3px);
-webkit-transition: .3s ease-in-out;
transition: .3s ease-in-out;
}
.hover07 figure:hover img {
-webkit-filter: blur(0);
filter: blur(0);
}
<div class="hover07 column">
<div>
<figure><img src="https://picsum.photos/300/200?image=244" /></figure>
<span>Hover</span>
</div>
<div>
<figure><img src="https://picsum.photos/300/200?image=1024" /></figure>
<span>Hover</span>
</div>
</div>

How to do this image hover effect in CSS : dark overlay + image grow + title on it?

Does anyone knows how to do in css the following effect on hover on a image (dark overlay + image grow + name which appears on it) : https://drive.google.com/file/d/1zP5gRnI7BZIO-ajHSrZg2LnNhZCJ_f5F/view?usp=sharing
Thank you very much :)
My practice is to create wrapper element around img tag
<div class="img-container">
<img src="./images/img.png" alt="foo" />
</div>
and then applying styles like
.img-container {
position: relative;
border-radius: 10px;
overflow: hidden;
}
.img-container:hover .overlay {
opacity: 1;
}
.img-container:hover img{
transform: scale(1.2);
}
.img-container::before {
content: "Hello";
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
font-size: 20px;
text-transform: uppercase;
font-weight: bold;
line-height: 25px;
color: #fff;
text-align: center;
background-color: rgba(175, 175, 175, 0.425);
pointer-events: none;
opacity: 0;
transition: opacity 0.3s;
}
img {
transition: transform 0.3s;
}
Hope this help ;)
You can either create a parent element appending the image element inside or use the ::after selector:
img {
position: relative;
}
img:hover {
/* grow image here */
}
img:hover::after {
contents: "FLUO";
display: flex;
background-color: rgba(0, 0, 0, 50%);
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
justify-content: center;
align-items: center;
}
Or use the background-image property to grow your image:
img {
background-image: url("/path/to/your/image.png");
background-position: center;
background-repeat: no-repeat;
background-size: contain;
position: relative;
}
img:hover {
background-size: 120%;
}

Rotated text glitchy in safari during sibling animation

Here's a codepen
I have this structure
body {
background-color: #1e1f26;
color: #fff;
font-size: 20px;
}
.card {
color: white;
width: 150px;
background-color: lightblue;
position: relative;
z-index: 0;
height: 180px;
border-radius: 10px;
overflow: hidden;
box-shadow: 0 0 0 rgba(#000, 0.5);
transition: box-shadow 0.3s;
}
.card .description {
background-color: rgba(#fff, 0.5);
height: 100%;
box-sizing: border-box;
padding: 10px;
transition: 0.3s;
opacity: 0;
transform: translateY(10%);
}
.card:hover .description {
opacity: 1;
transform: translateY(0);
}
.card .label {
display: block;
position: absolute;
width: 100%;
transform: rotate(-45deg);
text-align: center;
bottom: 15%;
right: -30%;
background: #f31;
}
<div class="card">
<div class="description">
Lalala
</div>
<div class="label">
LABEL
</div>
</div>
Label is rotated -45 deg
Description has opacity: 0 by default, but on hover is shown
This works perfectly fine in chrome, butt in safari label text gets glitchy or somewhat blurry during the description transition.
What can cause this? Is there a fix?

Have a transparent when hover each images(not background)

I have this code
<div class="photo">
<img src="images.jpg">
<div class="text">Its transparent</div>
</div>
I have tried this css
.text{
opacity:0.8;
background-color:#ccc;
position:fixed;
width:100%;
height:100%;
top:0px;
left:0px;
z-index:1000;
}
also this
.text{
background: rgba(0, 0, 0, 0.28) none repeat scroll 0 0;
color: #fff;
position: relative;
top: -240px;
width:100%;
height:100%
}
I want to the text above in images(not a background) with transparent background. I does have a transparent but it doesnt cover the whole images. I have tried this but doesnt apply to me.
Allow a div to cover the whole page instead of the area within the container
Background images: how to fill whole div if image is small and vice versa
Have a background image with a transparent colour
You could set .photo { position: relative; } then use position: absolute; to .text
div.photo .text {
position: absolute;
top: 0; right: 0; bottom: 0; left: 0;
}
Try on: https://jsfiddle.net/mmouze3n/1/
Edit 1 -
Adding a blur overlay by :before
div.photo .text {
position: absolute;
top: 0; right: 0; bottom: 0; left: 0;
text-align: center;
font-size: 26px;
color: #fff;
z-index: 1;
webkit-transition: .3s;
transition: .3s;
}
div.photo:hover .text { font-size: 100px; color: #000; }
div.photo:before {
display: inline-block;
content: '';
position: absolute;
top: 0; right: 0; bottom: 0; left: 0;
background-color:#ccc;
opacity: 0;
z-index: 0;
webkit-transition: .3s;
transition: .3s;
}
div.photo:hover:before {
opacity:0.8;
}
JSFiddle: https://jsfiddle.net/mmouze3n/2/

Shivering text with CSS transitions

I've tried creating a ripple effect on hover over with a button, the only problem I have is that the text shakes/rattles/shivers when I hover over it, I want it to stay still for a smooth transition. Any ideas on how to stop this?
a {
display: block;
position: relative;
width: 300px;
height: 50px;
background: rgba(0, 0, 255, .2);
text-decoration: none;
text-align: center;
overflow: hidden;
margin: 10% auto;
}
p,
span:first-of-type,
span:last-of-type {
position: absolute;
margin: 0;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 0;
height: 0;
border-radius: 50%;
transition: all .3s;
}
span:first-of-type {
transition-delay: .1s;
z-index: 1;
}
span:last-of-type {
transition-delay: .2s;
z-index: 2;
}
span.cta {
color: #33C;
text-transform: uppercase;
font-family: Arial;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 300px;
display: block;
transition: color .3s;
z-index: 3;
}
a:hover p,
a:hover span:first-of-type,
a:hover span:last-of-type {
width: 110%;
height: 660%;
border-radius: 50%;
background: rgba(0, 0, 255, .2);
}
a:hover span:first-of-type,
a:hover span:last-of-type {
width: 100%;
height: 100%;
}
a:hover p span {
color: #FFF;
}
<a href="#">
<p>
<span></span>
<span class="cta">Shop the Trend</span>
<span></span>
</p>
</a>
N.B. It's fine in IE11, it happens in every other browser.
Here you go...Modified HTML[added button text inside div and applied new class "textCta" to it]
<span class="cta"><div class="textCta">Shop the Trend</div></span>
CSS
.textCta {
color:#33C;
text-transform:uppercase;
font-family:Arial;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
width: 300px;
display: block;
transition: color .3s;
z-index: 3;
}
Demo
By deleting the p tags and placing the actual text within a div, I managed to stop the shivering and still keep the background effect the same.
Thanks to Nofi for their help.
<a href="#">
<span></span>
<div class="cta">Shop the Trend</div>
<span></span>
</a>

Resources