CSS3 : Fade in on hover and Fade out when hover is gone - html

I have a div. When I hover on it , it should be appeared using fadeIn effect and when I remove mouse then it should gone using fadeOut effect.
I have tried the below code.
.main_div{
width:100px;
height:100px;
border:thin black solid;
position:relative;
}
.main_div .overlay_div{
position:absolute;
top:0;
right:0;
bottom:0;
left:0;
width:100%;
height:100%;
display:none;
background:rgba(0,0,0,0.5);
opacity: 0;
transition: opacity;
transition-timing-function: ease-out;
transition-duration: 100ms;
transition-delay: 1s;
-ms-transition: opacity;
-ms-transition-timing-function: ease-out;
-ms-transition-duration: 100ms;
-ms-transition-delay: 1s;
-moz-transition: opacity;
-moz-transition-timing-function: ease-out;
-moz-transition-duration: 100ms;
-moz-transition-delay: 1s;
-webkit-transition: opacity;
-webkit-transition-timing-function: ease-out;
-webkit-transition-duration: 100ms;
-webkit-transition-delay: 1s;
}
.main_div:hover .overlay_div{
display:block;
opacity: 1;
/* Fade in */
transition: opacity;
transition-timing-function: ease-out;
transition-duration: 100ms;
-ms-transition:opacity;
-ms-transition-timing-function: ease-out;
-ms-transition-duration: 100ms;
-moz-transition:opacity;
-moz-transition-timing-function: ease-out;
-moz-transition-duration: 100ms;
-webkit-transition: opacity;
-webkit-transition-timing-function: ease-out;
-webkit-transition-duration: 100ms;
}
<div class="main_div">
<div class="overlay_div">
some text
</div>
</div>
Any help would be great.
Thank You.

CSS Transitions don't work on display:block/none; You can manage to give that effect using visibility/opacity properties.
Check this example, You can manually add the transition-delay property if you really want it to add.
.main_div {
width: 100px;
height: 100px;
border: thin black solid;
position: relative;
}
.main_div .overlay_div {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.5);
visibility: hidden;
opacity: 0;
transition: all 1s ease-out;
}
.main_div:hover .overlay_div {
visibility: visible;
opacity: 1;
transition: all 1s ease-in;
}
<div class="main_div">
<div class="overlay_div">
some text
</div>
</div>

Code work fine just change display from none to block, as transition doesn't works when changing display.
.main_div .overlay_div{
position:absolute;
top:0;
right:0;
bottom:0;
left:0;
width:100%;
height:100%;
display:block;/*Change this*/
......
......
}

Related

How to transition an item to move to the left on hover

I would like my element (which i have named as a class benefits-button) to slide in from the left upon hover. I have created the following two sets of css rules but I am having no luck:
.benefit-buttons {
transition-property: color, left;
transition-duration: 200ms;
transition-delay: .1s;
transition-timing-function: ease-in-out;
}
.benefit-buttons:hover {
opacity: 1;
color: #FF0000;
left: 50%;
}
.benefit-buttons {
-webkit-transition: all 1s ease-in-out;
-moz-transition: all 1s ease-in-out;
-o-transition: all 1s ease-in-out;
-ms-transition: all 1s ease-in-out;
width:100px;
height:100px;
background:red;
}
.benefit-buttons:hover {
opacity: 1;
color: #FF0000;
transform:translate(50%);
}
<div class="benefit-buttons"></div>
An element cannot have a left property unless it's absolutely-positioned (read more). Try a left margin as an alternative:
.benefit-buttons {
width: 25%;
transition-property: all;
transition-duration: 200ms;
transition-delay: .1s;
transition-timing-function: ease-in-out;
}
.benefit-buttons:hover {
opacity: 1;
color: #FF0000;
margin-left: 10%;
}
Demo

Make an image go dark and text appear when hovered over

I am trying to create an effect when I hover over an image, the image goes dark (so the opacity goes down) and text appears. The effects is basically this towards the bottom: http://www.ohmy.io/ . I can do one of the effects on their own, but doing both together they are almost fighting each other and goes dark for half a second then back light.
.vividworknav {
width: 33.333%;
height: auto;
float: left;
padding: 0;
-webkit-transition: opacity 0.5s ease-out;
-moz-transition: opacity 0.5s ease-out;
-o-transition: opacity 0.5s ease-out;
transition: opacity 0.5s ease-out;
}
.vividworknav:hover .work-text-content {
visibility: visible;
opacity: 1.0;
}
.vividworknav:hover {
opacity: 0.3;
}
.work-text-content {
width: 33.333%;
height: auto;
visibility: hidden;
z-index: 100;
position: absolute;
color: white;
left: 0%;
top: 25%;
font-size: 24px;
text-align: center;
-webkit-transition: visibility opacity 2.0Ms;
}
<div class="vividworknav">
<img src="http://www.gettyimages.co.uk/gi-resources/images/Homepage/Category-Creative/UK/UK_Creative_462809583.jpg" />
<div class="work-text-content">
<p>VIVID VAPOURS</p>
</div>
</div>
I added a black background to the parent element vividworknav, then I just set the opacity of the image and text on hover and then it seems to work fine.
.vividworknav {
width: 33.333%;
height: auto;
float: left;
padding: 0;
position: relative;
background-color: black;
}
.vividworknav:hover img {
opacity: 0.3;
}
.vividworknav:hover .work-text-content {
opacity: 1;
}
.vividworknav img {
padding: 0;
width: 100%;
display: block;
opacity: 1;
}
.vividworknav img,
.work-text-content {
-webkit-transition: opacity 0.5s ease-out;
-moz-transition: opacity 0.5s ease-out;
-o-transition: opacity 0.5s ease-out;
transition: opacity 0.5s ease-out;
}
.work-text-content {
position: absolute;
color: white;
left: 0;
top: 25%;
right: 0;
bottom: 0;
font-size: 24px;
text-align: center;
opacity: 0;
}
<div class="vividworknav">
<img src="http://www.gettyimages.co.uk/gi-resources/images/Homepage/Category-Creative/UK/UK_Creative_462809583.jpg" />
<div class="work-text-content">
<p>VIVID VAPOURS</p>
</div>
</div>
.vividworknav{
width:33.333%;
height:200px;
float:left;
padding:0;
-webkit-transition: opacity 0.5s ease-out;
-moz-transition: opacity 0.5s ease-out;
-o-transition: opacity 0.5s ease-out;
transition: opacity 0.5s ease-out;
background-image: url("http://www.gettyimages.co.uk/gi-resources/images/Homepage/Category-Creative/UK/UK_Creative_462809583.jpg");
}
.vividworknav:hover .work-text-content{
opacity: 1.0;
}
.work-text-content{
background-color: rgba(0,0,0,0.8);
width:33.333%;
height:100%;
opacity: 0;
z-index:100;
position:absolute;
color:white;
left:0%;
font-size:24px;
text-align:center;
-webkit-transition: all 500ms cubic-bezier(0.420, 0.000, 0.580, 1.000);
-moz-transition: all 500ms cubic-bezier(0.420, 0.000, 0.580, 1.000);
-o-transition: all 500ms cubic-bezier(0.420, 0.000, 0.580, 1.000);
transition: all 500ms cubic-bezier(0.420, 0.000, 0.580, 1.000); /* ease-in-out */
-webkit-transition-timing-function: cubic-bezier(0.420, 0.000, 0.580, 1.000);
-moz-transition-timing-function: cubic-bezier(0.420, 0.000, 0.580, 1.000);
-o-transition-timing-function: cubic-bezier(0.420, 0.000, 0.580, 1.000);
transition-timing-function: cubic-bezier(0.420, 0.000, 0.580, 1.000); /* ease-in-out */
}

Trying to use hover to make an image disappear but text is in the way

On tumblr I am trying to add an image to the bottom of the page that will disappear when moused over. As it disappears I have a block of text the transitions to appear in its place. Right now both are doing these things, but when the text block is moused over the image reappears. I want it to stay completely transparent.
This is in it's current state
#bite
#bite a{
display:block
}
#bite .death {
margin-top:0px;filter: alpha(opacity = 0);
opacity:0;-webkit-transition: all 0.5s ease-out;
-moz-transition: all 0.5s ease-out;transition: all 0.5s ease-out;
}
#bite:hover .death {
margin-top:0px;
-webkit-transition: all 0.8s ease-out;
-moz-transition: all 0.8s ease-out;
transition: all 0.8s ease-out;
filter: alpha(opacity = 100);
filter: alpha(opacity = 100);
opacity:100;
}
#actualnews {
font-family: 'Rock Salt'; cursive
font-size:5px;
color: #b8b8b8;
width:150px;
height:auto;
padding-top:3px;
border:1px solid#b8b8b8;
margin-left: 30px;
margin-top:10px;
text-align:center;
position:fixed;
right:145px;
bottom:70px;
}
#thekey img{
width:150px;
margin-top: -40px;
margin-left: 45px;
position:fixed;
right:150px;
bottom:20px;
filter: alpha(opacity = 100);
opacity:100;
-webkit-transition: all 0.8s ease-out;
-moz-transition: all 0.8s ease-out;
transition: all 0.8s ease-out;
}
#thekey img:hover {
margin-top:0px;
-webkit-transition: all 0.8s ease-out;
-moz-transition: all 0.8s ease-out;
transition: all 0.8s ease-out;
filter: alpha(opacity = 0);
filter: alpha(opacity = 0);
opacity:0;
}
<div id="bite">
<div id="thekey"><img src="{image:thekey}"></div>
<div class="death">
<div id="actualnews">
<a href="www.winngstiel.tumblr.com/tagged/mine" font-color:#9d3e78>MY STUFF</a>
<p>
<a href="www.winngstiel.tumblr.com/tagged/edit" font-color:#9d3e78>PRETTY THINGS</a>
</div>
</div></div>
As you can see the text is somehow in the way. Any help is greatly appreciated as I am very new to how everything with coding works. Any confusion or questions please ask!
You can change the selector for the CSS rule that hides the image to trigger on #bite's hover.
...
#bite:hover #thekey img {
...
Full code:
#bite
#bite a{
display:block
}
#bite .death {
margin-top:0px;filter: alpha(opacity = 0);
opacity:0;-webkit-transition: all 0.5s ease-out;
-moz-transition: all 0.5s ease-out;transition: all 0.5s ease-out;
}
#bite:hover .death {
margin-top:0px;
-webkit-transition: all 0.8s ease-out;
-moz-transition: all 0.8s ease-out;
transition: all 0.8s ease-out;
filter: alpha(opacity = 100);
filter: alpha(opacity = 100);
opacity:100;
}
#actualnews {
font-family: 'Rock Salt'; cursive
font-size:5px;
color: #b8b8b8;
width:150px;
height:auto;
padding-top:3px;
border:1px solid#b8b8b8;
margin-left: 30px;
margin-top:10px;
text-align:center;
position:fixed;
right:145px;
bottom:70px;
}
#thekey img{
width:150px;
margin-top: -40px;
margin-left: 45px;
position:fixed;
right:150px;
bottom:20px;
filter: alpha(opacity = 100);
opacity:100;
-webkit-transition: all 0.8s ease-out;
-moz-transition: all 0.8s ease-out;
transition: all 0.8s ease-out;
}
#bite:hover #thekey img {
margin-top:0px;
-webkit-transition: all 0.8s ease-out;
-moz-transition: all 0.8s ease-out;
transition: all 0.8s ease-out;
filter: alpha(opacity = 0);
filter: alpha(opacity = 0);
opacity:0;
}
<div id="bite">
<div id="thekey"><img src="{image:thekey}"></div>
<div class="death">
<div id="actualnews">
<a href="www.winngstiel.tumblr.com/tagged/mine" font-color:#9d3e78>MY STUFF</a>
<p>
<a href="www.winngstiel.tumblr.com/tagged/edit" font-color:#9d3e78>PRETTY THINGS</a>
</div>
</div></div>

how can i set this button to appear with the transition

in my present code, button initially is visible and with the transition, it becomes hidden behind the box. What i want is "my button initially should be hidden and should appear with the transition". Thanks in advance..
P.S. No jQuery
<!DOCTYPE HTML>
<body>
<div id="anim">
</div>
<input type="button" value="this should be behind" id="btn" />
</body>
</html>
<style>
#anim{
z-index: 1;
position: absolute;
width: 300px;
height: 200px;
background-color: red;
-webkit-transition: all 2s;
-moz-transition: all 2s;
-ms-transition: all 2s;
-o-transition: all 2s;
transition: all 2s;
}
#anim:hover{
height:400px
}
#btn{
z-index: -1;
position:fixed;
margin-top: 300px;
}
</style>
You can set the opacity of the button on hover without changing the structure of your document using the adjacent sibling selector.
Here's how:
#anim:hover + #btn
{
opacity: 1;
}
Edit: You can also delay this using transition-delay on the button:
#btn
{
opacity: 0;
transition-delay: 700ms;
z-index: 2;
position:fixed;
margin-top: 300px;
}
Below is the complete CSS, as some changes were also made to initially hide the button, and to properly set the z-index property.
JSFiddle here.
#anim{
z-index: 1;
position: absolute;
width: 300px;
height: 200px;
background-color: red;
-webkit-transition: all 2s;
-moz-transition: all 2s;
-ms-transition: all 2s;
-o-transition: all 2s;
transition: all 2s;
}
#anim:hover{
height:400px
}
#anim:hover + #btn{
opacity: 1;
}
#btn{
opacity: 0;
transition-delay: 700ms;
z-index: 2;
position:fixed;
margin-top: 300px;
}
I think this is what you want:
#anim{
width: 300px;
height: 200px;
background-color: red;
-webkit-transition: width 2s ease;
-moz-transition: width 2s ease;
-ms-transition: width 2s ease;
-o-transition: width 2s ease;
transition: width 2s ease;
}
#anim:hover{
width: 600px;
}
#btn{
margin-left: 100px;
margin-top: 100px;
opacity:0;
-webkit-transition: opacity 2s linear;
-moz-transition: opacity 2s linear;
-ms-transition: opacity 2s linear;
-o-transition: opacity 2s linear;
transition: opacity 2s linear;
}
#anim:hover #btn{
opacity:1;
}
and add your button inside #anim div, just like this:
<div id="anim">
<input type="button" value="this should be behind" id="btn" />
</div>
and all this without javascript, only css.
JSBIN

CSS - tooltip only with css and html doesn't work

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.