How to "tint" image with css - html

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>

Related

CSS3 filters, transition not working on IE and Safari

As you can in my snippet when you run, I have a box and underneath that I have a sort of shadow which slow gets bigger if I hover over the box.
.container{
min-height: 400px;
overflow: auto;
clear: both;
background: red;
}
.content {
max-width: 100%;
width: 441px;
float: left;
text-align: center;
position: relative;
z-index: 2;
}
.content:after {
content: '';
position: absolute;
bottom: -10px;
left: 7px;
right: 0;
margin: 0 auto;
width: 228px;
height: 48px;
border-radius: 50%;
background: #000;
opacity: 0.5;
-webkit-filter: blur(25px);
-o-filter: blur(25px);
-webkit-transform: scale(1, 0.3);
-o-transform: scale(1, 0.3);
}
.content:hover:after {
width: 350px;
height: 80px;
transition: all .8s;
-webkit-transition: all .8s;
-o-transition: all .8s;
-moz-transition: all .8s;
}
<div class="container">
<div class="content">
<h3>Find Your</h3>
<div class="main_content">
<h3>Nearest</h3>
<p>Fryking</p>
</div>
</div>
</div>
How can I make this work on all browsers?
At the moment I only see it on chrome and firefox. When I go to IE and Safari my code does not work.
This is how it looks on chrome:
And here how it looks on safari and IE:
Hope you can help
On the MDN website it says that IE currently has no support for filter CSS property and unluckily I can't see a way to fix this.
MDN css filter
However there are 2 alternatives
Use a picture with transparency (like .png) of a circle gradient. You would need to create it in some kind of software like Adobe Photoshop or find online.
Then you could use it as a background-image in your CSS.
Use the radial-gradient for the background in CSS. (There are lots of websites for generating it)
Should work for:
background: radial-gradient(rgba(0,0,0,1), rgba(0,0,0,0))
(Requires -o- -moz- -webkit- for support in different browsers)
Finally set backgroud-size: 100% 100%

Hover effect in the image

I am attaching the image below ..Will any 1know how to give hover effect by css in this type of image
<a href="#top"><img class="popup1 img-1" src="assets/images/img-1.png" />
</a>
image
hover like this
if you have the two images, why not replace on hover. Dunno if that is what you meant in the first place.
.my-class:hover {
background-image: url('assets/images/img-2.png');
}
When you hover this will replace the imagine with the one you want.
What you want is to make a class to control the hover effect you want to add. This is done like so in CSS:
.classname:hover{
/*css stuff here*/
}
The recommended approach would be to have a different image after the user hovers over your image like so:
.classname:hover{
background-image: url('path to your image');
}
If you want to add an outline to the image then you can use drop-shadow, which is a quick-fix but I don't recommend, like so:
.classname:hover{
-webkit-filter: drop-shadow(1px 1px 0 yellow)
drop-shadow(-1px -1px 0 yellow);
filter: drop-shadow(1px 1px 0 yellow)
drop-shadow(-1px -1px 0 yellow);
}
Lets say you have this html file:
<!DOCTYPE html>
<html>
<head>
<style>
.container {
position: relative;
width: 50%;
}
.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%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%)
}
.container:hover .image {
opacity: 0.3;
}
.container:hover .middle {
opacity: 1;
}
.text {
background-color: #4CAF50;
color: white;
font-size: 16px;
padding: 16px 32px;
}
</style>
</head>
<body>
<div class="container">
<img src="http://combiboilersleeds.com/images/image/image-0.jpg" alt="" class="image" style="width:100%">
<div class="middle">
<div class="text">WOW Hover Effect</div>
</div>
</div>
</body>
</html>
This post has answer of how to make shadow for custom shape images, based on that you should be able to figure out how to make yellow shadow.
Drop shadow for PNG image in CSS
Here is an example of what you could do (just change the links to the area of your images and it should work.
JSFiddle
HTML
<a href="#top"><img class="popup1 img-1" src="https://i.stack.imgur.com/G9Sd7.png" />
</a>
CSS
.popup1:hover {
background-image: url(https://i.stack.imgur.com/D4EzQ.png)
}

Hover over an Image and another image appears

Hi i need help with some css/html
i want to hover over an image and then another image/text appears with the background image becoming opacity :0.5
<style>
.your-img {
width: 344px; /* your image width and height here */
height: 857px;
background-image: url('images/men.png');
}
.your-hover {
width: 341px;
height: 225px;
opacity: 0;
filter: alpha(opacity = 0);
background-image: url('images/men2.png');
align:bottom;
}
.your-hover:hover {
opacity: 0.5;
filter: alpha(opacity = 50);
}
</style>
<div class="your-img">
<div class="your-hover"></div>
</div>
this is the code i am using. men.png is the main image and the men2.png is the image that should appear when i hover over men.png.
but when i hover over men.png its opacity is 1 and the hovered image is 0.5
how do i make the background image 0.5 and the hovered image 1
As far as I know, there isn't a CSS only way to lower the opacity of the background image only. Also, the hover will have to be on the parent as the child cannot affect the parent's styling.
The tricky part is that if you lower the opacity of the parent, the child will also have its opacity lowered. To get around this, you can play with :after and applying a background: rgba() doing something like:
JS Fiddle
.your-img {
width: 344px;
/* your image width and height here */
height: 857px;
background-image: url('images/men.png');
position: relative;
}
.your-img:after {
content: '';
top: 0;
bottom: 0;
width: 100%;
display: inline-block;
background: rgba(0, 0, 0, 0);
position: absolute;
}
.your-hover {
width: 341px;
height: 225px;
opacity: 0;
filter: alpha(opacity=0);
background-image: url('images/men2.png');
align: bottom;
display: none;
}
.your-img:hover::after {
background: rgba(0, 0, 0, .5);
}
.your-img:hover .your-hover {
display: block;
opacity: 1;
filter: alpha(opacity=50);
}
if i understand the question correctly, you want hovering on the outer div to show the inner?
you just need to add a css rule for outer:hover > inner
.your-img:hover > .your-hover {
opacity: 0.5;
filter: alpha(opacity = 50);
}
Example
Hello you can simplify your code a lot but just having this css. There is no need to create a separate hover div. When you apply the pseudo class :hover to the .your-img class all you need to do is set the opacity there and the new url to your other background image.
.your-img {
width: 344px; /* your image width and height here */
height: 857px;
background-image: url('http://placehold.it/350x150');
}
.your-img:hover {
width: 341px;
height: 225px;
background-image: url('http://placehold.it/350x150');
opacity: 0.5;
Here is a fiddle to illustrate https://jsfiddle.net/gward90/25bcmmhb/
Your code has quite a few errors, particularly where the hover is. You need to have the hover on the parent. Also, in your code youu are trying to make the parent go to 0.5 opacity and the child to 1. This isn't possible, the child is inside the parent, and it will already be 0.5 opacity because the parent is, so you will never get it back to 1.
I have left 2 scripts for you to try below, the first is a modified version of yours which should get the hover working, but you will have issues with the opacity as i described above, the second is a modified html and style to give you an example of how it should be laid out.
Example
.your-img {
width: 344px; /* your image width and height here */
height: 857px;
background-image: url('images/men.png');
}
.your-img:hover .your-hover{
opacity: 0.5;
filter: alpha(opacity = 50);
}
.your-hover {
width: 341px;
height: 225px;
opacity: 0;
filter: alpha(opacity = 0);
background-image: url('images/men2.png');
align:bottom;
}
</style>
<div class="your-img">
<div class="your-hover"></div>
</div>
<style>
.parent {
width: 344px; /* your image width and height here */
height: 857px;
position: relative;
background-image: url('images/men.png');
}
.parent:hover .img-1{
opacity: 0.5;
filter: alpha(opacity = 50);
}
.parent:hover .img-2{
opacity: 0.5;
filter: alpha(opacity = 50);
}
.img-1 {
background-image: url('images/men.png');
position: absolute;
height: 100%;
width: 100%;
}
.img-2 {
background-image: url('images/men2.png');
position: absolute;
opacity: 0;
filter: alpha(opacity = 0);
width: 341px;
height: 225px;
bottom: 0;
}
</style>
<div class="parent">
<div class="img-1"></div>
<div class="img-2"></div>
</div>

hover appearing and disappearing

Right now I have an image that has another image absolutely positioned on top of the first one. Both images are inside an a tag.
I am trying to get it so that when I hover on any part of the first image, both the first image goes from .5 opacity to full, and the 2nd image goes from 0 opacity to full.
I've been able to make the hover work for the image but the 2nd image only activates it's opacity when I hover directly on it, rather than highlighting both when I'm on either of them.
<div class="of-volume image-column">
<a href="http://www.greatlengthshair.co.uk/hair-extensions/">
<img src="img/artistry-1-bg.jpg" alt="artisans of volume link" class="image-link">
<img src="img/artistry-1-icon.png" alt="" class="artisan-icon">
</a>
</div>
/*//////////////////////////////////////
IMAGE NAV
//////////////////////////////////////*/
.image-column {
background-color: black;
float: left;
width: 33.3333%;
position: relative;
margin-bottom: -3px;
}
.image-column a {
opacity: .5;
}
.image-column a:hover {
opacity: 1;
}
.artisan-icon {
position: absolute;
margin-right: auto;
margin-left: auto;
right: 0;
left: 0;
bottom: 25px;
}
You have mixed up most of your CSS rules. Just attach the desired effects to the correct hover state:
.image-link { opacity: 0.5; }
.artisan-icon { opacity: 0; }
a:hover .image-link { opacity: 1; }
a:hover .artistan-icon { opacity: 1; }
I put both absolute images inside a relative div, then did set the :hover selector on this container.
body {
width: 100%;
height: 100%;
margin: 0px;
}
#container {
position:relative;
width:100%;
height:200px;
}
img {
position:absolute;
top: 0px;
left:0px;
width:100%;
height:200px;
-webkit-transition: opacity 1s; /* Safari */
transition: opacity 1s;
}
#pic1 {
opacity:0.0;
}
#pic2 {
opacity:0.5;
}
#container:hover #pic1, #container:hover #pic2 {
opacity: 1;
}
<div id=container>
<img id=pic1 class=picture src="http://i.imgur.com/tMVGqP6.jpg" alt=img>
<img id=pic2 class=picture src="http://i.imgur.com/Goy7oBy.gif" alt=img>
</div>

Turing image that hovers transparent into an image button

so i have created an image button and i gave it a transparent black hover attribute. For some reason the image is not a "button" anymore, but it still has the hover effect. Is there any way that i can keep the button attribute while still having the color?
http://jsfiddle.net/cp14rbpa/1/
What i am thinking is that the transparent hover overlay overrides the image button attribute. I am not sure if that is the problem though.
<body>
<div class="image">
<input type="image" src="img/testor.jpg" name="saveForm" class="btTxt submit" id="saveForm" />
</div>
</body>
.image {
position:relative;
width:726px;
height:549px;
}
.image img {
width:100%;
vertical-align:top;
}
.image:after {
content:'\A';
position:absolute;
width:100%; height:100%;
top:0; left:0;
background:rgba(0,0,0,0.6);
opacity:0;
transition: all 0.5s;
-webkit-transition: all 0.5s;
}
.image:hover:after {
opacity:1;
}
I guess you want something like this :)
.image {
position: relative;
width: 726px;
height: 549px;
}
.image a {
display: block;
z-index: 2;
position: relative;
}
.image img {
width: 100%;
vertical-align: top;
}
.image a:after {
content: '\A';
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
background: rgba(0, 0, 0, 0.6);
opacity: 0;
transition: all 0.5s;
-webkit-transition: all 0.5s;
}
.image a:hover:after {
opacity: 1;
}
<div class="image">
<a href="#">
<img src="http://www.golfdigest.com.sg/files/u1/726x549-instruction.jpg" alt="Clickable" />
</a>
</div>
Use the <button> tag instead of the <a> tag. Like here