<div> with blur on hover to stay blurred after unhovering - html

I have two divs, one carrying the content, the other one existing for the sole purpose of having a background image set to blur on hover.
Both of them are placed in a single container, appear as they should, though the problem is that when I hover over the content div, logically (given the structure of the code I've written), the blur rule set to the background div is no longer active.
My question is how can I get it to work so that when I hover over the content div, the background stays blurred, or whether it is even achievable through pure HTML/CSS
.col-lg-6 {height: 100%; margin: auto; padding: 0; border: none}
.container {height: 100%; ; background: #333333; }
.content {position: absolute; z-index: 10;}
.bg {height: 100%;; background-image: url(bg.jpg);
-webkit-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
-ms-transition: all 0.5s ease;
transition: all 0.5s ease;}
.bg:hover {-webkit-filter: blur(15px);}
<a href="#">
<div class="col-lg-6 col-sm-12">
<div class="container">
<div class="content">
<img src="icon.png" class="img-responsive">
<h2>Icon</h2>
</div>
<div class="bg">
</div>
</div>
</div>
</a>

You can check for the mouseover event and then set a class to the element, so it will stay with the "blurred" effect.
You can use jQuery for that, as below:
$(document).ready(function () {
$('.bg').on('mouseover', function() {
$(this).addClass('bg-hovered');
});
});
And the class:
.bg-hovered {-webkit-filter: blur(15px);}
See fiddle working: https://jsfiddle.net/guschnwg/bg03hb6k/

You need to change the :hover pseudo-class to your .container class.
Instead of this:
.bg:hover {
-webkit-filter: blur(15px);
}
Do this:
.container:hover .bg {
-webkit-filter: blur(15px);
}
This way, even if you hover the .content element, the blur will still be applied.
.container {
height: 100%;
background: #333333;
position: relative;
}
.content {
position: relative;
z-index: 10;
}
.bg {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: url(http://fillmurray.com/1000/500) no-repeat center center / cover;
transition: all 0.5s ease;
}
.container:hover .bg {
-webkit-filter: blur(15px);
}
<div class="container">
<div class="content">
<img src="http://placehold.it/50x50" class="img-responsive">
<h2>Icon</h2>
</div>
<div class="bg"></div>
</div>

Related

Incompatible css changes on children on parent hover

I have the following html code :
.logo {
display: inline-block;
width: 30px;
position: absolute;
top: 50%;
opacity: 0;
transition: 0.6s;
}
.container:hover .logo {
opacity: 1;
transition: 0.6s;
}
.container:hover .picture {
filter: brightness(0.7);
transition: 0.6s;
}
<div class="container">
<div class="element-header">
<div class="element">Foo</div>
<div class="element">Bar</div>
</div>
<div class="loader"> </div>
<img src="logo.png" alt="" class="logo">
<img src="picture.jpg" alt="" class="picture">
</div>
When .container is hovered, I want .logo to be at opacity:1 and .picture to be at filter: brightness(0.7).
When a try to apply those properties one-by-one at .container hover, each is working. But when both are set-up, only the filter one is working.
If you set the position to relative instead of absolute, both images will display. As the code stood, one image was getting lost. (I substituted my own images in and added a picture class to size the image)
The transition works fine though!
Try below:
.logo {
display: inline-block;
width: 100px;
//height:auto;
position: relative;
top: 50%;
opacity: 0;
transition: 0.6s;
}
.picture {
width: 500px;
height: auto;
float: left;
}
.container:hover .logo {
opacity: 1;
transition: 0.6s;
}
.container:hover .picture {
filter: brightness(0.7);
transition: 0.6s;
}
<div class="container">
<div class="element-header">
<div class="element">Foo</div>
<div class="element">Bar</div>
</div>
<div class="loader"> </div>
<img src="https://www.dcu.ie/sites/default/files/afu_logo2_1.jpg" alt="agefriendly" class="logo">
<img src="http://www.rachelgallen.com/images/mountains.jpg" alt="Mountains" class="picture">
</div>
Fiddle here

How to "tint" image with css

I try to tint an image with the background attribute like this:
.image-holder:hover {
opacity: 1;
transition: opacity 1s, background 1s;
background: #EBEFF7;
}
.image-holder {
height: 250px;
width: 200px;
opacity: 0.5;
transition: opacity 1s, background 1s;
}
<div class="image-holder">
<img src="https://dummyimage.com/200x200/fff/000000.png" />
</div>
http://jsfiddle.net/6ELSF/1047/
But the image is not "tinted" like expected.
On hover it looks like this:
but I want it to look like this:
I tried to test some solution I found regarding overlay of images but neither worked in my example.
How do accomplish this in the least complicated manner?
I used some combined filters for tinting an image completely. Tinting is not possible directly (with filters), but you can paint it sepia, adapt saturation and brightness, and get the desired color by using hue-rotate... I think it was something like this ...
img {
filter: sepia(100%) saturate(300%) brightness(70%) hue-rotate(180deg);
}
You will need to adapt it to your needs.
Depending on your browser support use filter, many options at your disposal, caniuse.com looks promising http://caniuse.com/#search=css%20filter :-
filter: blur(5px);
filter: brightness(0.4);
filter: contrast(200%);
filter: drop-shadow(16px 16px 20px blue);
filter: grayscale(50%);
filter: hue-rotate(90deg);
filter: invert(75%);
filter: opacity(25%);
filter: saturate(30%);
filter: sepia(60%);
Using :before selector you can tint images with different colors
.image-holder {
height: 200px;
width: 200px;
position:relative;
}
.image-holder:before {
content: "";
display: block;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: rgba(0,255,255, 0.5);
transition: all .3s linear;
}
.image-holder:hover:before {
background: none;
}
<div class="image-holder">
<img src="http://lorempixel.com/200/200" />
</div>
You can achieve this using mix-blend-mode which currently has ~88% support. You can use the same markup as before.
<div class="image-holder">
<img src="https://dummyimage.com/200x200/fff/000000.png" />
</div>
But use this css:
div.image-holder {
transition: background-color .2s;
width: min-content;
}
div.image-holder:hover {
background-color: #EBEFF7;
}
img {
display: block;
/* Blend with parents background: */
mix-blend-mode: multiply;
}
For this demo you are wanting to tint whites towards your chosen color so you want to use the multiply blend mode. If you are wanting to tint blacks then use the screen blend mode.
Codepen Demo
Changing the opacity of the parent container changes all children. make a separate div to control your tint. I hammered something together, but the essentials are there.
.image-holder {
position: relative;
max-height: 250px;
max-width: 200px;
}
.image-holder img {
display: block;
opacity: 0.5;
max-width: 100%;
max-height: inherit;
}
.tint {
position: absolute;
max-height: 250px;
max-width: 200px;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: 0;
opacity: 0;
background: #00f;
transition: opacity 1s;
}
.image-holder:hover .tint {
opacity: 1;
}
<div class="image-holder">
<div class='tint'></div>
<img src="http://lorempixel.com/200/200" />
</div>
It's not exactly a real tint but this is the way I find easier to achieve a color layer over an image. The trick is to use an absolute layer with rgba color over an image. It works perfectly for my general cases.
Have a go!
.mycontainer{
position:relative;
width:50%;
margin:auto;
}
.overtint {
position:absolute;
background-color: rgba(255,0,0,0.6);
width:100%; height:100%;
}
img{ width:100%;}
a:hover .overtint {
background-color: rgba(0,255,0,0.6);
transition-duration: .5s;
}
<div class="mycontainer">
<a href="#">
<div class="overtint"></div>
<img src="https://via.placeholder.com/300x150">
</a>
</div>

Partial change on parent hover, full change on element hover

I'd like to have a UI element fade in slightly when hovering on its parent div, then fade in completely when hovering on the UI element itself. But it seems that if I set the parent hover, hovering on the child doesn't do anything.
HTML:
<div id="parent">
<div id="child">
</div> <!-- end child -->
</div> <!-- end parent -->
CSS:
#parent {
width: 200px;
height: 200px;
background-color: black;
}
#child {
width: 100px;
height: 100px;
background-color: white;
opacity: 0.3;
}
/* fades in partially, looks nice */
#parent:hover #child {
opacity: 0.6;
}
/* doesn't seem to do anything! */
#child:hover {
opacity: 1;
}
JSFiddle version
The problem is that the rule #parent:hover #child has higher priority than #child:hover because it describes more elements in the DOM tree.
For increasing the priority of #child:hover there are two ways:
Describe it more precisely with
#parent #child:hover
Add !important to opacity: 1:
opacity: 1 !important;
Fiddle
#parent {
width: 200px;
height: 200px;
background-color: black;
}
#child {
width: 100px;
height: 100px;
background-color: white;
opacity: 0.3;
}
#parent:hover #child {
opacity: 0.6;
}
#parent #child:hover {
opacity: 1;
}
<div id="parent">
<div id="child">
</div> <!-- end child -->
</div> <!-- end parent -->
PS: You might also want to add a transition.
It's a specificity issue. The #parent:hover #child selector is "winning out" over #child:hover. Change the second to #parent:hover #child:hover (or just #parent #child:hover), and you should be set. https://jsfiddle.net/1khjo42q/1/
Add transitions
#child {
width: 100px;
height: 100px;
background-color: white;
opacity: 0.3;
/* added these */
-webkit-transition: background-color 500ms ease-out 1s;
-moz-transition: background-color 500ms ease-out 1s;
-o-transition: background-color 500ms ease-out 1s;
transition: background-color 500ms ease-out 1s;
}

Image hover caption with zoom effect in bootstrap

I am unable to align image to the width of caption with maintaining the gutter width. I am using bootstrap and also the image is flowing outside the div on hover. Can anybody help me out ?
This is what i am trying to achive : https://awwapp.com/s/43b68655-83a6-4133-ab28-0ec9a4152316/
Pen : http://codepen.io/anon/pen/XbxOMq
HTML :
HOTSPOT TEXTf
<div class="col-md-4 hotspot-wrapper">
<img src="https://newevolutiondesigns.com/images/freebies/hd-widescreen-wallpaper-3.jpg" alt="..." class="img-responsive">
<div class="hotspot-text">
HOTSPOT TEXTf
</div>
</div>
</div>
<div class="col-md-4 hotspot-wrapper">
<img src="https://newevolutiondesigns.com/images/freebies/hd-widescreen-wallpaper-3.jpg" alt="..." class="img-responsive">
<div class="hotspot-text">
HOTSPOT TEXTf
</div>
</div>
</div>
CSS:
.hotspot-wrapper {
position: relative;
overflow: hidden;
margin-bottom:20px;
}
.hotspot-text {
width:100%;
height: 102px;
position: absolute;
bottom: -50px;
transition: all .2s linear;
background: rgba(0,0,0,.7);
color:#fff;
}
.hotspot-wrapper:hover .hotspot-text {
bottom: 0;
}
.hotspot-wrapper img {
-webkit-transition: all 0.7s ease;
transition: all 0.7s ease;
}
.hotspot-wrapper:hover img {
-webkit-transform:scale(1.3);
transform:scale(1.3);
}
You should make your CSS for these two classes like this, so the hotspot for the text will be aligned with the image :
.hotspot-text {
height: 102px;
position: absolute;
bottom: -50px;
right:0px;
left:0px;
transition: all .2s linear;
background: rgba(0,0,0,.7);
color:#fff;
}
.hotspot-wrapper:hover .hotspot-text {
bottom: 0;
left:0;
right:0;
}
And you should overwrite the padding on the left and on the right set there by default with bootstrap. Like that, the image will have the full width of the div.
.col-lg-4 ,.col-md-4,col-sm-4,col-xs-4{
padding-left:0px;
padding-right:0px;
}
Here's a Fiddle

Change position of div on hover

Consider following HTML.
I have .image and .details wrapped in .wrap. Outside the .wrap, I have another div .extra, which I want to hide initially but on hover over the image div only, i want to slide it down so that it takes whole area of the .wrap.
I am trying following code, does not work:
HTML:
<div class="box">
<div class="wrap">
<div class="image"><img src="http://farm9.staticflickr.com/8075/8310628243_d48e64dc66_m.jpg" /></div>
<div class="details">xxx</div>
</div>
<div class="extra">hidden, show on hover over .image</div>
</div>
CSS:
.box{
border: 1px solid red;
width: 240px;
}
.image{
border: 1px solid green;
position: relative;
}
.extra{
position: absolute;
top: -100%;
left: 0;
background: green;
}
.box .image:hover .extra{
top: 0;
}
Demo: http://jsfiddle.net/pv9jd/
.extra is not a child of .image.
I updated the fiddle by replacing .image with .wrap:hover.
http://jsfiddle.net/UrKCs/2/
I'm not sure if you want that, because now the .extra appears when hovering the whole .wrap div.
I updated it again to have the hover on the image only
http://jsfiddle.net/UrKCs/5/
I believe you are looking for something like this image hover using jQuery
$('.image').hover(function(){
$('.extra').css({'top' : '0'});
},function(){
$('.extra').css({'top' : '-100%'}
);
});​
Sorry to butcher your code but this may be able to help you:
<div class="box">
<div class="image"></div>
</div>
This is the CSS:
.box div{
color: #fff;
width: 200px;
height: 100px;
position: relative;
box-sizing: border-box;
transition: border .7s ease;
}
.image{
background: #fff url(http://farm9.staticflickr.com/8075/8310628243_d48e64dc66_m.jpg) bottom;
border-top: solid 100px #ccc;
}
.image:hover{
-webkit-transition: all .5s ease;
-moz-transition: all .5s ease;
-o-transition: all .5s ease;
transition: all .5s ease;
border: solid 0px;
}
You can read more here for the sliding.
You can also play around here: http://codepen.io/joe/pen/oqxJu