I know my question may look weird at first, but let me explain...
I have a div, named subcontainer which contains two elements :
Two icons and a link.
Basically, I want the div to make the two icons disappear on hover, BUT not my link. Here is my code :
<div class="subcontainer">
<img class="icons" src="images/arrow_right.png"/>
Follow me
<img class="icons" src="images/arrow_left.png"/>
</div>
**Edit : I want the icons to disappear on subcontainer:hover. Not on icons:hover.
If you have any questions to help me, just ask! :)
Use psuedo selectors:
View Here: http://jsfiddle.net/SinisterSystems/hajt6/3/
By doing it this way, you are telling it to only target the img elements that are children of the .subcontainer, but also allowing you to target the entire div without affecting the a element.
<div class="subcontainer">
<img class="icons" src="https://cdn3.iconfinder.com/data/icons/ose/Arrow%20Right.png"/>
Follow me
<img class="icons" src="https://cdn3.iconfinder.com/data/icons/ose/Arrow%20Right.png"/>
</div>
CSS
.subcontainer:hover > img {
transition: 0.2s;
opacity: 0;
}
If you want to make the image fade, use the following CSS:
.icons{
transition: all 0.5s; /*how long you want the fade to last*/
}
.icons:hover{
opacity:0;
}
Here's a fiddle: http://jsfiddle.net/74wPn/
EDIT: Revised to fit asker's comment's needs.
.icons{
transition: all 0.5s; /*how long you want the fade to last*/
}
.subcontainer:hover .icons{
opacity:0
}
Updated fiddle: http://jsfiddle.net/74wPn/1/
Do this way:
.icons:hover {
display: none;
}
If you want it to disappear instantly:
.icons:hover {
display: none;
}
If you want it to do it over a set time period:
.icons:hover {
transition: 0.2s;
opacity: 0;
}
You can use jquery.
$(".icons").hover(function(){
$(".icons").hide();
});
Related
I can see it working on Microsoft's website: https://developer.microsoft.com/en-us/microsoft-edge/testdrive/demos/css3filters/
But on the website I am currently working on, it only works some times.
For example, when I remove max-width on the img tag, the grayscale suddenly works, but then when I hover it, it stops working.
The filter was originally on an img tag, but I also tried on a div with the same result.
I know it might be too specific a case, but I can't seem to find anything related to this that might work. Is there some properties known to mess with filters in Edge?
EDIT
After tweaking around in the inspector, I have found that hiding a pseudo-element solves the grayscale bug.
.Cta:before {
position: absolute;top: 50%;left: 0;right: 0;bottom: 0;
display: block;content: '';z-index: 1;
background: -webkit-gradient(linear,left top,left bottom,color-stop(0,hsla(0,0%,100%,0)),to(#fff));
background: -webkit-linear-gradient(top,hsla(0,0%,100%,0),#fff);
background: linear-gradient(180deg,hsla(0,0%,100%,0) 0,#fff);
-webkit-transition: opacity .2s ease;
transition: opacity .2s ease;
}
Code sample
<div class="Cta">
<div class="cta-image">
<img src="{{baseUrl}}{{image}}" alt="{{title}}" />
</div>
<div class="cta-content">
<h3 class="cta-title">{{{title}}}</h3>
<h4 class="cta-subtitle">{{subtitle}}</h4>
</div>
</div>
CSS:
.Cta {position:relative;}
.Cta .cta-image {filter:grayscale(100%);opacity:0.2;}
.Cta img {display:block;width:100%;}
.Cta .cta-content {position:absolute;bottom:0;left:0;right:0;padding:0 30px 30px;}
Finally found the culprit, removing the z-index from my pseudo-element was clearing the bug.
Putting z-index on each element to specifically tell the order instead of relying on browser defaults resolved the problem of the grayscale filter not being applied.
.Cta {position:relative;}
.Cta:before {position:absolute;top:50%;left:0;right:0;bottom:0;z-index:2;content:'';background:/*gradient*/;}
.Cta .cta-image {position:relative;z-index:1;filter:grayscale(100%);opacity:0.2;}
.Cta img {display:block;width:100%;}
.Cta .cta-content {position:absolute;bottom:0;left:0;right:0;z-index:3;padding:0 30px 30px;}
This question already has answers here:
how to cancel opacity for a child element?
(2 answers)
Closed 6 years ago.
I would like to set opacity to a parent div but not 1 particular child div.
So i have a html code like:
body {
background-image: url(http://url.jpg)
}
#main {
opacity: 0.9;
}
#slider {
opacity: 1;
}
<body>
<div id="main">
<div id="slider">
</div>
<div id="content-wrapper">
</div>
</div>
</body>
Obviously this won't work. The whole #main div is now transparant to the background div. That is what i want but not the #slider div. For some reason, when only setting opacity to the #content-wrapper, nothing happens at all.
Any ideas?
Edit:
I can't use an rgba color, since i would like the background image to come through. Could you explain why adding opacity to #content-wrapper is not working?
Maybe with rgba or hsla color code can help
#someParent {
background: rgba(0,0,0,0.5);
}
I want to create a black transparent overlay on 4 images, keeping the size and if possible add some text with the hover. I've looked preview answers but it doesn't work for me. Begginer. Could you help me ?
HTML
<section class="image">
<img src="images/JOHN.jpg" alt="john" id="John" >
<img src="images/CITIES.jpg" alt="cities" id="Cities">
<img src="images/HOMIES.jpg" alt="homies" id="Homies">
<img src="images/HASARD1.jpg" alt="hasard" "Hasard">
</section>
CSS
img {
width: 47%;
height: auto;
}
#John:hover {
background: black;
;
opacity: 0.7;
/* i also tried */
background: rgba(0, 0, 0, 0.7))
/* the only thing that works on it is the opacity */
}
section.image {
text-align: center;
}
Thank you
The background you are trying to apply will not appear on the <img> tags because your image is blocking it out.
Think of your <img> tag as a layered element, the top is your actual picture, and below it is the container where the background is set. Since your image fills up the entire container, your background will never appear.
What you want to do instead is create an element that appears on-top of your image, and appears upon hover.
In order to do this, you need to first wrap your <img> tags with an element, like this:
<a href="#" class="img-link">
<img class="image" src="http://placehold.it/350x150" />
</a>
I used an <a> tag because I'm assuming you want something clickable.
Next we can apply some basic styling that inserts an element after the <a> tag, and makes it appears upon hover. The result is something like this:
.img-link {
display: inline-block;
line-height: 0;
position: relative;
}
.img-link:after {
background: rgba(0,0,0,0.3);
display: inline-block;
content: '';
height: 100%;
opacity: 0;
position: absolute;
top: 0;
bottom: 0;
width: 100%;
transition: opacity 0.2s linear;
}
.img-link:hover:after {
opacity: 1; /* show overlay */
}
<a href="#" class="img-link">
<img class="image" src="http://placehold.it/350x150" />
</a>
A quick google of "CSS image caption hover" reveals a lot of links which you'll find useful :) Take this for example: http://demo.hongkiat.com/css3-image-captions/index.html
Basically you cannot just do it with an img. You need some additional HTML around it to create the black background. For example, here's a very basic jsfiddle: https://jsfiddle.net/outfg5ym/
Notice how I've wrapped my img inside a div:
<div class="black">
<img src="http://placekitten.com.s3.amazonaws.com/homepage-samples/408/287.jpg">
</div>
The div creates a black background behind the image, and then when hovering over the div, the opacity of the image is dropped back.
You may add a filter to image to achieve similar effect.
Something like this:
img:hover {
-webkit-filter:brightness(70%);
filter:brightness(70%);
}
Example: https://jsfiddle.net/d6tce9g8/1/
Also, there are a lot of filters available: https://developer.mozilla.org/en/docs/Web/CSS/filter
Browser support of filter: http://caniuse.com/#search=filter
I am using CSS buttons to create an image gallery in which the :focus state is used to enlarge each image when clicked and the ":active" state is used to display a description of the image when it is clicked again. When the button is unclicked, the description is hidden, and when the user clicks elsewhere, either the image returns to thumbnail size or a different image is enlarged. Here's my CSS:
div.img button{
-webkit-transition: width 2s, height 2s, ease .25s;
transition: width 2s, height 2s, ease .25s;
}
.mdT {
display:inline-block;
width:100px;
height:100px;
margin:2px;
border:0px;
outline:0px;
vertical-align:top;
background-color:inherit;
}
.mdT:focus {
width:500px;
height:500px;
background-position: left top;
background-repeat:no-repeat;
background-color: inherit;
}
.mdT:active {
margin-bottom: 25px;
}
.mdI1 { background-image:url(01a.jpg); }
.mdI1:focus { background-image:url(01.jpg); }
.mdI2 { background-image:url(02a.jpg); }
.mdI2:focus { background-image:url(02.jpg); }
.mdI3 { background-image:url(03a.jpg); }
.mdI3:focus { background-image:url(03.jpg); }
.mdI4 { background-image:url(04a.jpg); }
.mdI4:focus { background-image:url(04.jpg); }
And here's my html:
<div class="img">
<h2>Image Set 1</h2>
<button class="mdT mdI1" ></button>
<button class="mdT mdI2" ></button>
<button class="mdT mdI3" ></button>
<button class="mdT mdI4" ></button>
</div>
A few notes:
I'd like the image descriptions to appear within the space created by the 25px margin during the :active state.
I will adjust the width and height of these elements later, once I get all the source images sorted out. For now I'm using placeholders resembling my StackOverflow profile pic, just to make sure they work.
Mainly I'm not sure what kind of code I need, where to put it, and how to adjust it so that it's unique to each button.
I'm fairly new to writing in computer languages so in your responses please assume I know absolutely nothing about what I'm doing. Thanks!
I have an image which its background changes in hover and I want to add hover to it.
here is what I want to add:
-webkit-transition: all 1s ease-in-out;
And it is the online version:
http://jsfiddle.net/jmXdh/2/
DEMO
This is the solution that you are searching for!
HTML CHANGES
<a href="/">
<img class="imghover" src="http://i42.tinypic.com/2v9zuc1.jpg"/>
<img class="img" src="http://i40.tinypic.com/i3s4dc.png"/>
</a>
CSS IMPROVEMENTS
.img{
z-index:1;
margin-left: -190px;
margin-bottom:5px;
opacity:0;
-webkit-transition:opacity 0.5s;
}
.img:hover{
opacity:1;
}
.imghover{
z-index:-100;
}
Some CSS properties can't be animated, including background-image. See https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_animated_properties