I have a css image hover effect, in which the image in the div turns to 0 opacity and then the background image is displayed. This means as your hover, one image fades out and the other appears.
This effect uses CSS and webkit.
But the issue is that when you hover over the image the effect takes place but not in reverse, meaning it does not fade in when you leave the image. But that is the effect I want.
This is the HTML markup...
<div id="info"><img src="infow1.png" width="800" height="800" /></div>
This is the CSS markup...
#info {
background: url(infow2.png) 0 0 no-repeat;
position: fixed;
top: 50%;
left: 50%;
margin-top: -400px;
margin-left: -400px;
width: 800px;
height: 800px;
z-index:100;
opacity: 1;
-webkit-transition: opacity;
-webkit-transition-timing-function: ease-out;
-webkit-transition-duration: 500ms;
}
#info img:hover{
opacity:0;
-webkit-transition: opacity;
-webkit-transition-timing-function: ease-out;
-webkit-transition-duration: 500ms;
}
So overall I want the infow.png to fade out, when hover over the image then fade back in when you leave.
Is this what you are looking for?
HTML:
<img src="infow1.png" class="fadeOut">
CSS3:
.fadeOut {
opacity: 1;
transition: opacity .25s ease-in-out;
-moz-transition: opacity .25s ease-in-out;
-webkit-transition: opacity .25s ease-in-out;
}
.fadeOut:hover {
opacity: 0;
}
JS Fiddle: http://jsfiddle.net/AXQW4/1/
EDIT: If you want to display a different image when hovering, you can add it as a background-image behind the original: http://jsfiddle.net/8qzcY/
You've created no rules that apply to the unhovered-image, so if you create some rules, as such:
#info img {
opacity: 1;
-webkit-transition: opacity;
-webkit-transition-timing-function: ease-out;
-webkit-transition-duration: 500ms;
}
JS Fiddle demo.
It should work as you wish.
For contrast, the same demo without the unhovered #info img rules: JS Fiddle demo, which seems to match your description.
Related
I'm trying to create an image hover effect, but I'm having 1 of two 2 issues:
The text AND the background are opaque (I only want the background to be opaque. I want the text to stay normal.)
The image will hover and transition correctly, but then if I hover over the text, the whole image goes back to the original version of the image.
I've tried several different methods, but I can't get past both of those issues at the same time. So what I want to accomplish is:
-Start with an opaque image and normal color text, and then upon hover, the image goes normal and the text stays the same, and all of the image stays normal while the cursor is over the image.
Here's my code:
.outer {
opacity: 0.25;
-webkit-transition: all .5s ease;
-moz-transition: all .5s ease;
-o-transition: all .5s ease;
-ms-transition: all .5s ease;
transition: all .5s ease;
}
.outer:hover{
opacity: 1.0;
cursor: pointer;
}
h2.image-headings {
position: absolute;
top: 40%;
width: 100%;
font-size: 60px;
color: #fff;
}
<div class="outer">
<img src="http://wasatchhospitality.com/wp-content/uploads/2017/02/wasatch-elements.jpg">
<h2 class="image-headings">Management Team</h2>
</div>
This code shows the text and image starting off opaque. Thanks
If you just want to change the opacity of the image, change your rules to change/transition opacity on the image - not the parent div.
.outer img {
opacity: 0.25;
-webkit-transition: all .5s ease;
-moz-transition: all .5s ease;
-o-transition: all .5s ease;
-ms-transition: all .5s ease;
transition: all .5s ease;
}
.outer {
cursor: pointer;
}
.outer:hover img {
opacity: 1.0;
}
h2.image-headings {
position: absolute;
top: 40%;
width: 100%;
font-size: 60px;
color: #fff;
}
<div class="outer">
<img src="http://wasatchhospitality.com/wp-content/uploads/2017/02/wasatch-elements.jpg">
<h2 class="image-headings">Management Team</h2>
</div>
I recommend you to use a JQuery plugin to do this because they are pretty good animated and its easy to
/* CSS used here will be applied after bootstrap.css */
body{
background-color:yellow;
}
img{
-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;
}
img:hover{
-webkit-filter:blur(5px);
}
<img src="http://i.stack.imgur.com/K0jNI.png">
When you hover over the image the borders of the image flash for a bit before settling.. Is there a way to fix that?
And how do i make a text show up on the middle of the image when i hover over it?
EDIT: This now looks great in Chrome
I don't think it's entirely possible to get a super clean transition when using webkit blur. I've had a lot of rendering issues and glitches when using it before. It's a resource hog too when used on a lot of elements. My advice to change your easing to linear and target only the blur. That should tighten it up a little bit.
img{
-webkit-transition: -webkit-filter 0.5s linear;
-moz-transition: -webkit-filter 0.5s linear;
-o-transition: -webkit-filter 0.5s linear;
-ms-transition: -webkit-filter 0.5s linear;
transition: -webkit-filter 0.5s linear;
}
As for the text fade in. You'll need to add in an element that is initially opacity:0; but then changed to opacity:1; when the parent block is hovered. Initial HTML changed to this:
<div class='block'>
<img src="https://www.nasa.gov/sites/default/files/styles/image_card_4x3_ratio/public/thumbnails/image/leisa_christmas_false_color.png?itok=Jxf0IlS4">
<span>Hey there</span>
</div>
And the new CSS
/* CSS used here will be applied after bootstrap.css */
body {
background-color: yellow;
}
img {
-webkit-transition: -webkit-filter 0.5s linear;
transition: -webkit-filter 0.5s linear;
}
.block {
position: relative;
width: 400px;
}
.block img {
width: 100%;
}
.block span {
opacity: 0;
-webkit-transition: all .3s;
transition: all .3s;
color: white;
position: absolute;
top: 50%;
-webkit-transform: translateY(-50%);
transform: translateY(-50%);
text-align: center;
left: 0;
right: 0;
}
.block:hover > span {
opacity: 1;
}
img:hover {
-webkit-filter: blur(4px);
}
Example here
http://codepen.io/jcoulterdesign/pen/58d613e80e4a768cc9e54aa1e7aaa0af
HTML:
<a class="navbar-brand page-scroll" href="#intro"></a>
CSS:
.navbar-custom .nav li a.navbar-brand {
width: 70px;
height: 62px;
background: url(myimg.png) no-repeat;
background-size: 70px 62px;
display: block;
position: relative;
text-indent: -9999px;
-webkit-transition: all .2s linear;
-moz-transition: all .2s linear;
-o-transition: all .2s linear;
-ms-transition: all .2s linear;
transition: all .2s linear;
}
.navbar-custom .nav li a.navbar-brand:hover {
background: url(myimghover.png) no-repeat;
}
The hover effect works fine in every browser, but the transition effect works in Google Chrome only and I really can't explain why. I've already tried using sprite images and pseudo-element hover, but my images have a transparent background so, on hover, the "bottom" image remains partially visible. Any idea?
Thank you in advance.
Regards,
J.
try
-webkit-transition-duration: 0.2s;
-moz-transition-duration: 0.2s;
-o-transition-duration: 0.2s;
transition-duration: 0.2s;
You can't animate background-image. https://www.w3.org/TR/css3-transitions/#animatable-properties
I am trying to do simple tooltip only with css3 and html, but the transition doesn't work. What am I doing wrong?
HTML
<p>
This has tooltip
</p>
<div class="tooltip">Tooltip content</div>
CSS
p {
width: 200px;
background-color: aqua;
padding: 10px;
margin-top: 50px;
}
div.tooltip {
position: absolute;
width: auto;
padding: 10px;
background-color: rgba(0,0,0, 0.5);
top: 0px;
display: none;
opacity: 0.0;
transition: opacity 1s;
-webkit-transition: opacity 1s;
-o-transition: opacity 1s;
-moz-transition: opacity 1s;
}
p:hover + div.tooltip {
display: block;
opacity: 1.0;
transition: opacity 1s;
-webkit-transition: opacity 1s;
-o-transition: opacity 1s;
-moz-transition: opacity 1s;
}
http://jsfiddle.net/MCDg4/
Update / Alternate solution
For a modern browser CSS3 solution you could use pseudo elements..
<span data-tooltip="I am the tooltip">This has a tooltip</span>
and
[data-tooltip]{
position:relative;
}
[data-tooltip]:before{
content:attr(data-tooltip);
position:absolute;
bottom:110%;
padding:10px;
background:#666;
opacity:0;
color:white;
font-size:smaller;
-webkit-transition:opacity 1s ease;
-o-transition:opacity 1s ease;
transition:opacity 1s ease;
pointer-events:none;
}
[data-tooltip]:hover:before{
opacity:1;
}
Demo at http://jsfiddle.net/BJ2tr/
(this could be done without pseudo-elements by nesting the tooltip inside the elements that it refers to, and adjusting the css accordingly)
Unfortunately when you change display from none to something else, you cannot have transitions.
Instead of display:none you could just offset it outside of the window (with top:-9999px) and bring it to position when showing it.
div.tooltip {
position: absolute;
width: auto;
padding: 10px;
background-color: rgba(0,0,0, 0.5);
top: -999px; /*CHANGED THIS AND REMOVED display:none*/
display: none;
opacity: 0.0;
transition: opacity 1s;
-webkit-transition: opacity 1s;
-o-transition: opacity 1s;
-moz-transition: opacity 1s;
}
p:hover + div.tooltip {
opacity: 1.0;
top: 0px; /*ADDED THIS AND REMOVED display:block*/
transition: opacity 1s;
-webkit-transition: opacity 1s;
-o-transition: opacity 1s;
-moz-transition: opacity 1s;
}
This will, however, not fade out (only in) since it moves it away on mouseout (so it actually does fade but you do not see it because it is outside the viewport)..
Explanation
You put transition only on opacity, while when changing to display:block; it is shown as a block with opacity:1; by default.
Solution
(JSFiddle)
Delete the display:none; and display:block on your tooltip element.
On the image hover, I want to display a different small image on it with a background and opacity so that the original image is still visible. I want to use the transition to slow the hover effect.
So here's what I'm trying and not working:
HTML:
<img src="http://i50.tinypic.com/2poy3kl.jpg" class="test" />
CSS:
.test {
background: red url("http://i50.tinypic.com/10mue4k.png");
transition: background .25s ease-in-out;
-moz-transition: background .25s ease-in-out;
-webkit-transition: background .25s ease-in-out;
}
.test:hover {
opacity: 0.5;
}
JS Fiddle:
http://jsfiddle.net/AXQW4/2/
Can someone please help me with this?
You'll need an additional wrapper for this. Exactly the size of the image, and give that the background. Then, when you hover over the image, you hide it and the underlying background is revealed.
Live example
HTML
<div class="background">
<img src="http://i50.tinypic.com/2poy3kl.jpg">
</div>
CSS
* {
padding: 0;
margin: 0;
-webkit-box-sizing: border-box;
}
.background {
background: url("http://i50.tinypic.com/10mue4k.png");
display: inline-block;
font-size: 0;
}
.background img {
-webkit-transition: all .5s;
}
.background img:hover {
opacity: 0.5;
}
No need to know the exact dimensions of the image.
Is this something you were looking for: http://jsfiddle.net/AXQW4/3/
One more demo :)
http://jsfiddle.net/AXQW4/7/
Is this what you want Demo
Or this LINK
.test {
background: red url("http://i50.tinypic.com/10mue4k.png");
-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;
}
.test:hover {
opacity:.5;
}