I have these social media icons, when the mouse hovers on one icon its should fade into a other icon. I thought of something like this:
HTML:
<div class="socials">
<img src="../images/fb.png" id="fb1" />
<img src="../images/fb-hover.png" id="fb2" />
<img src="../images/twitter.png" id="twitter1" />
<img src="../images/twitter-hover.png" id="twitter2" />
<img src="../images/insta.png" id="insta1"/>
<img src="../images/insta-hover.png" id="insta2" />
</div>
CSS:
/*This is for letting them stack on each other*/
#fb2, #twitter2, #insta2 {
display:none;
position:absolute;
}
/*Fade animation*/
#fb1:hover, #twitter1:hover, #insta1:hover {
opacity: 0.0;
transition: opacity .55s ease-in-out;
-moz-transition: opacity .55s ease-in-out;
-webkit-transition: opacity .55s ease-in-out;
}
Or check this jsfiddle.
The fading out works correctly. But the 'background' image (so the '...-hover.png' image) won't show up. How do I make this work?
Thanks!
If you set display to block on your #fb2, #twitter2, and #insta2, you can see the problem - it's the positioning. In your solution you would need to absolutely position each hover icon under the normal icon. I don't think it can be flexible.
So, I propose a more flexible solution.
Introduce this syntax:
<div class="socials">
<div class="icon">
<img src="http://sillyquark.com/images/fb.png" class="normal" />
<img src="http://sillyquark.com/images/fb-hover.png" class="hover" />
</div>
<div class="icon">
<img src="http://www.sillyquark.com/images/twitter.png" class="normal" />
<img src="http://www.sillyquark.com/images/twitter-hover.png" class="hover" />
</div>
<div class="icon">
<img src="http://www.sillyquark.com/images/insta.png" class="normal" />
<img src="http://www.sillyquark.com/images/insta-hover.png" class="hover" />
</div>
</div>
Put each icon in a div with a class of of .icon and inside put two images.
Set the .icon div's position to relative to allow absolute positioning relative to the .icon, instead of the body element. Set each icon's top and left to 0px, and add transitions to all images. Also, add width to .icon and img.
.icon{
float: left;
position: relative;
width: 45px;
height: 45px;
padding: 20px;
}
.icon img{
transition: opacity .55s ease-in-out;
-moz-transition: opacity .55s ease-in-out;
-webkit-transition: opacity .55s ease-in-out;
opacity: 1.0;
position: absolute;
width: 45px;
top: 0;
left: 0;
}
This is how you switch opacities. In normal conditions, set .icon .normal's opacity to 1.0, and .icon .hover's opacity to 0.0. On hover, do the oposite.
.icon .hover { opacity: 0.0; }
.icon:hover .hover { opacity: 1.0; }
.icon:hover .normal { opacity: 0.0; }
Check out this fiddle for the demo http://jsfiddle.net/uUk6N/3/
Related
I started a project in Notepad++ and I would like to create a slider on hover while using CSS. The problem is that I do not know if my picture (which I wanted to create a slider with) needs to be separated in 2 images or 1 merged picture. I also don't know if translate3d works in notepad++.
Here's what my HTML looks like:
<div class="college">
<img src="image.png" />
and here's my current CSS:
body {
background: url("anotherimage.png") 33em 0% fixed no-repeat;
background-color: rgb(0,85,170);
}
.college {
margin-left: 100px;
margin-top: 325px;
overflow: hidden;
}
.college img {
}
.college img:hover {
}
edit
hello again, after we've found out about my problem with hovering sliding images, i managed to make my own ligns of codes but now im stuck into another problem, while i was douing my code my images were going behind the background which i liked it very much but when i finished all of it, it stopped douing it ,i've tried using overflow: hidden and postion: absolute but i don't really get how it works especially since when i search what their fonction does. and i thought i was douing right but it seems it doesn't change anything at all,
so i would like to know how i manage to make my moving pictures to go out of the screen/ hide inside the background.
here what my css looks like
` .college .image {
margin-left: 100px;
margin-top: 475px;
position: absolute
}
.college .imagesecond {
transform: translate(0px,500px);
transition: transform 1s ease-in-out 0.2s;
border-radius: 8px;
overflow: hidden
}
.college:hover > .imagesecond{
transform: translate(0,-200px);
}
.lycee .image {
margin-left: 700px;
margin-top: 500px;
position: absolute
}
.lycee .imagefourth{
transform: translate(0px,500px);
transition: transform 0.9s ease-in-out 0.2s;
border-radius: 8px;
overflow: hidden
}
.lycee:hover > .imagefourth{
transform: translate(0,-500px);
}
.formation .image{
margin-left: 1250px;
margin-top:510px;
overflow: hidden;
}
.formation .imagesixth{
transform: translate(0px,100px);
transition: transform 1s ease-in-out 0.2s;
border-radius: 8px;
overflow: hidden
}
.formation:hover > .imagesixth{
transform: translate(0 ,-75
0px);`
here is my html
<div class="saintemarie">
<a href="">
<div class="college">
<img class="image imagefirst" src="choixcollege.png" />
<img class="image imagesecond" src="pepepls.gif"/>
</div>
</a>
<a href="lyceesaintemarie.html">
<div class="lycee">
<img class="image imagethird" src="choixlyceepro.png" />
<img class="image imagefourth" src="pepepls.gif" />
</div>
</a>
<a href="c&fsaintemarie.html">
<div class="formation">
<img class="image imagefifth" src="choix
centre&formation.png" />
<img class="image imagesixth" src="pepepls.gif" />
</div>
</div>
</a
I'm not fully sure what you're asking but is this what you're wanting? If so you're more interested in transitions or animations, hover within the blue border
https://jsfiddle.net/gevfeqk9/24/
.college {
margin: auto;
overflow: hidden;
border: 1px solid blue;
}
.college .image-1{
transform: translate(-280px,0);
transition: transform 1s ease-in-out 0s;
}
.college .image-2{
transform: translate(-560px,0);
transition: transform 1s ease-in-out 0s;
}
.college:hover .image-1,.college:hover .image-2{
transform: translate(0,0);
}
I'm using this to create a mouseover effect:
<a href="http://glim.pt/produtos/cadeiras">
<img src="http://glim.pt/wp-content/uploads/2017/02/cadeiras_categoria-300x300.png"
onmouseover=" this.src='http://glim.pt/wp-content/uploads/2017/02/cadeiras_cat2-300x300.png';"
onmouseout=" this.src='http://glim.pt/wp-content/uploads/2017/02/cadeiras_categoria-300x300.png';">
</img>
</a>
But I wanted it to be smoothly, how can I add fade effect? It's for a Wordpress page.
You can accomplish this using CSS transitions, if you aren't opposed to it as detailed in this blog post on crossfading images:
/* A wrapper for your images to transition */
.transition-wrapper {
position:relative;
height:300px;
width:300px;
margin:0 auto;
}
/* Position each image and apply a transition */
.transition-wrapper img {
position:absolute;
left:0;
-webkit-transition: opacity 1s ease-in-out;
-moz-transition: opacity 1s ease-in-out;
-o-transition: opacity 1s ease-in-out;
transition: opacity 1s ease-in-out;
}
/* Automatically hide an image during hover (to reveal the other one) */
.transition-wrapper img:last-of-type:hover {
opacity:0;
}
And then simply update your markup accordingly :
<a class='transition-wrapper' href="http://glim.pt/produtos/cadeiras">
<img src='http://glim.pt/wp-content/uploads/2017/02/cadeiras_cat2-300x300.png' />
<img src='http://glim.pt/wp-content/uploads/2017/02/cadeiras_categoria-300x300.png' />
</a>
Example
/* A wrapper for your images to transition */
.transition-wrapper {
position:relative;
height:300px;
width:300px;
margin:0 auto;
}
/* Position each image and apply a transition */
.transition-wrapper img {
position:absolute;
left:0;
-webkit-transition: opacity 1s ease-in-out;
-moz-transition: opacity 1s ease-in-out;
-o-transition: opacity 1s ease-in-out;
transition: opacity 1s ease-in-out;
}
/* Automatically hide an image during hover (to reveal the other one) */
.transition-wrapper img:last-of-type:hover {
opacity:0;
}
<a class='transition-wrapper' href="http://glim.pt/produtos/cadeiras">
<img src='http://glim.pt/wp-content/uploads/2017/02/cadeiras_cat2-300x300.png' />
<img src='http://glim.pt/wp-content/uploads/2017/02/cadeiras_categoria-300x300.png' />
</a>
Sounds like your going to want to add some javascript to that.
I recommend using the jQuery library.
https://jquery.com/
Here you can find a bunch of different fade effects and the documentation
http://api.jquery.com/
With jQuery:
$('a').hover(function(){
$(this).children().fadeOut(100, function(){
$(this).children().remove();
});
$(this).append($('<img src="http://glim.pt/wp-content/uploads/2017/02/cadeiras_cat2-300x300.png"</img>').hide().fadeIn(2000));
}, function(){
$(this).children().fadeOut(100, function(){
$(this).children().remove();
});
$(this).append($('<img src="http://glim.pt/wp-content/uploads/2017/02/cadeiras_categoria-300x300.png"></img>').hide().fadeIn(2000));
});
a {
display: block;
width: 300px;
height: 300px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<a href="#">
A link
<img src="http://glim.pt/wp-content/uploads/2017/02/cadeiras_categoria-300x300.png"></img>
</a>
Some quick example, but you'll have to fix the issue of the image, that fades in, while the first image fades out. But the post above has much more better solution via css.
<div class="fadehover">
<img src="cbavota-bw.jpg" alt="" class="a" />
<img src="cbavota.jpg" alt="" class="b" />
</div>
If this is what you mean? or what you are looking for? I tried to answer to the best of my ability.
I have an image that has an ease-in-out opacity effect when I hover over it. I like the transition effect but not the color of the image when I hover over it. I can't figure out to change the color of my images when I hover over them. background-color: #50b948; does nothing. What am I doing wrong? Here is my CSS and HTML below.
#about img {
margin: 0 auto;
}
.imgAbout img {
opacity: 1;
transition: opacity .25s ease-in-out;
-moz-transition: opacity .25s ease-in-out;
-webkit-transition: opacity .25s ease-in-out;
}
.imgAbout img:hover {
background: #50b948;
opacity: 0.6;
}
HTML
<div class="row">
<div class="col-md-4">
<a href="bios/teamBioNeil.html">
<div class="imgAbout">
<img src="img/team/neil580x410.jpg" class="img-responsive" alt="Bio">
</div>
</a>
<h1>NAME</h1>
<h3>Chairman & CEO<br>
Senior Wealth Advisor</h3>
</div>
<div class="col-md-4">
<a href="bios/teamBioJeff.html">
<div class="imgAbout">
<img src="img/team/neil580x410.jpg" class="img-responsive" alt="Bio">
</div>
</a>
<h1>NAME</h1>
<h3>President<br>
Senior Wealth Advisor</h3>
</div>
<div class="col-md-4">
<a href="bios/teamBioKim.html">
<div class="imgAbout">
<img src="img/team/kim580x410.jpg" class="img-responsive" alt="Bio">
</div>
</a>
<h1>NAME</h1>
<h3>Chief Operating Officer</h3>
</div>
</div> <!-- end row -->
you want to apply the background color of the div that contains the image - rather than the image itself - then when you reduce the opacity of the image the background will show through.
.imgAbout{
background: #50b948;
}
.imgAbout img {
opacity: 1;
transition: opacity .25s ease-in-out;
-moz-transition: opacity .25s ease-in-out;
-webkit-transition: opacity .25s ease-in-out;
}
.imgAbout img:hover {
opacity: 0.6;
}
and incidentally - you have too many H1's - semantically you should only have 1 H1 per page (or section) and then the others are H2's eg: page H1 could be "Staff" and then each named below would be H2's or 3's.
I'm trying to figure out, how to have two divs that would react to onmouseover event. One should overlay with picture the other, whereas the bottom div should contain another image and other elements such as buttons, text etc. Could you please show me, how I need to adjust my code, to make it work?
HTML:
<div id="container">
<div id="bottom" >
<img id="image" src="http://curiousanimals.net/wp-content/uploads/2008/04/cat-programmer.jpg"/>
<p id="text">
Hello World!
</p>
</div>
<div id="top">
<img id="cat" src="http://www.vetprofessionals.com/catprofessional/images/home-cat.jpg" />
</div>
</div>
CSS:
#container img {
position:absolute;
height:400px;
width:400px;
left:0;
-webkit-transition: opacity 1s ease-in-out;
-moz-transition: opacity 1s ease-in-out;
-o-transition: opacity 1s ease-in-out;
transition: opacity 1s ease-in-out;
}
#top img:hover {
opacity:0;
}
#text{
z-index:100;
position:absolute;
color:white;
font-size:24px;
font-weight:bold;
left:150px;
top:350px;
}
This is what I've got so far. But I'd need to display the Hello world only when bottom image is displayed.. As well if I'd have some button there, to make it react only in those situations.
http://jsfiddle.net/L7XCD/733/
The easiest way if you just want clickable elements on the bottom element, would be to just switch the top and bottom layer. So you make your top layer (including button and text) transparent and lay it over the visible image.
On hover you just blend it in.
If you do it the other way around the top image is blocking the clickevents.
I put a little example together here:
http://jsfiddle.net/L7XCD/732/
HTML:
<div class="container">
<div class="cat-image bottom">
<img class="cat" src="http://www.vetprofessionals.com/catprofessional/images/home-cat.jpg" />
</div>
<div class="cat-image top" >
<img class="image" src="http://curiousanimals.net/wp-content/uploads/2008/04/cat-programmer.jpg"/>
<p class="text">
Hello World!
</p>
<button>Click meow!</button>
</div>
CSS:
.top {
position: relative;
opacity: 0;
-webkit-transition: opacity 1s ease-in-out;
-moz-transition: opacity 1s ease-in-out;
-o-transition: opacity 1s ease-in-out;
transition: opacity 1s ease-in-out;
}
.top:hover {
opacity: 1;
}
.bottom {
position: absolute;
top: 0;
}
#top {
z-index: 10;
position: relative;
}
#bottom #text {
z-index: 1;
}
That should do the trick.
I have two images. One over the other.
When I resize the browser window, the images must be placed at the same position. How do I achieve that?
Here is my html code:
<div id="stars-container">
<div id="star-1" class="stars"
data-1000p="position:absolute;opacity:0;"
data-1010p="position:absolute;opacity:1;"
>
<img src="img/stars/1.png" alt="">
</div>
</div><!-- end of stars-container -->
<!-- Pegasus bg starts -->
<div class="pegasus"
data-1000p="opacity:0;"
data-1270p="opacity:1;">
<img src="img/stars/horse1.png">
</div>
<!-- Pegasus bg ends -->
</div>
</div>
And here is its CSS:
#stars-container{
height:60%;width:50%;display:block;
position:relative;
top:14%;left:20%;z-index:9;
}
.stars{
position:relative;
z-index:9;
}
.stars img{
position:absolute;
width:100%;
}
#star-1{top:25%;left:30%;}
#star-2{top:20%;left:33.5%;}
#star-3{top:25%;left:35%;}
#star-4{top:30%;left:39%;}
#star-5{top:29.5%;left:41.5%;}
#star-6{top:35%;left:42.5%;}
#star-7{top:35%;left:51.5%;}
#star-8{top:30%;left:52.5%;}
#star-9{top:44%;left:48.5%;}
#star-10{top:55.5%;left:47.1%;}
#star-11{top:53%;left:42%; }
#star-13{top:56%;left:37.5%;}
#star-14{top:62%;left:33%;}
#star-15{top:54%;left:42%;}
#star-16{top:49.5%;left:37%;}
#star-17{top:52%;left:33%;}
#star-18{top:51.5%;left:30%;}
.pegasus{
width:50%;height:50%;
position:relative;left:20%;
top:-40%;
}
.pegasus img{
position:absolute;
width:100%;
}
So, basically there is an image of image of pegasus below the group of 18 stars. I am doing it for a parallax website.
You could add style tag to html code.
style="position:fixed;width:36px; height:36px; left:60px;top:50px"
For you the important parameters are left(x) and top(y).
You can use following code
<style>
.image1{
background : url('<path to image1>') no-repeat;
}
.image2{
background : url('<pat to image2>') no-repeat;
}
</style>
<div class="image1">
<a class="image2" href="#" style="left: 10px; top: 92px;"></a>
</div>
Above code will set image 1 as background image. I have used anchor tag for image above image1. You can use your own tag eg. img. Important thing is style that should be used is left and top. This will locate the image2 on top of image1 from 10px left and 92px top with repect to div's top, left = (0,0)
Try image cross fading.
More Info and demo :here
or fiddle
#cf {
position:relative;
height:281px;
width:450px;
margin:0 auto;
}
#cf img {
position:absolute;
left:0;
-webkit-transition: opacity 1s ease-in-out;
-moz-transition: opacity 1s ease-in-out;
-o-transition: opacity 1s ease-in-out;
transition: opacity 1s ease-in-out;
}
#cf img.top:hover {
opacity:0;
}
<div id="cf">
<img class="bottom" src="http://addnectar.co.in/ovenfresh/ovenfresh/admin/files/products/Sunny-29-07-2014-img-06-07-40.jpg" />
<img class="top" src="http://addnectar.co.in/ovenfresh/ovenfresh/admin/files/products/Sunny-29-07-2014-img-07-45-01.jpg" />
</div>