-webkit-transition: property isn't working in a bubble element?

218 Views Asked by At

I was creating a portfolio, and I want it so that whenever someone hovers over my name, a bubble with an arrow appears. I've done that part already, but the problem is that the -webkit-transition property isn't working. The bubble is a little far to my name so I want it so that it takes a little bit of time to hide again, so someone can go to it easily because I'm thinking of making a form to contact me in it.

My HTML:

<div id="side-bar"><h1 id="ab_me">About Me</h1>
<img src="saksham.png" id="saksham">
<p id="name"><span>S</span>aksham <span>C</span>hauhan</p>

<div id="bubble">
SUP !
<div id="bubble-arrow-border">
</div>
<div id="bubble-arrow">
</div>
</div>

</div>

My CSS:

div#side-bar p
{
font-size:25;
border-bottom:2px solid red;
position:absolute;
left:10px;
color:#F63737;
}
div#side-bar p:hover
{
border-bottom:2px groove #C01F1F;
color:#C01F1F;
text-shadow:0px 1px 2px #F98378;
-webkit-transition:1s;
}
div#side-bar p span
{
font-size:40px;
}
div#side-bar p:hover ~ #bubble
{
display:block;
visibility:visible;
opacity:1;
-webkit-transition:5s;
}
div#side-bar p #bubble:hover
{
display:block;
visibility:visible;
opacity:1;
}
#bubble
{
background-color:#EDEDED;
visibility:hidden;
border:2px solid #666666;
font-size:35px;
line-height:1.3em;
padding:10px;
position:absolute;
text-align:center;
width:300px;
-moz-border-radius:15px;
-webkit-border-radius:15px;
-moz-box-shadow:0 0 5px #888888;
-webkit-box-shadow:0 0 5px #888888;
z-index:100;
left:230px;
top:400px;
display:none;
-webkit-transition:5s;
opacity:0;
}
#bubble-arrow
{
border-color:transparent #EDEDED transparent transparent;
border-style: solid;
border-width: 15px;
height:0;
width:0;
position:absolute;
bottom:25px;
left:-28px;
z-index:100;
}
#bubble-arrow-border
{
border-color:transparent #666666 transparent transparent;
border-style: solid;
border-width: 15px;
height:0;
width:0;
position:absolute;
bottom:25px;
left:-31px;
}
3

There are 3 best solutions below

1
On

You have to tell it what properties to transition. It looks like you're trying to do this:

transition:all 1s ease;
-webkit-transition:all 1s ease;
0
On

Don't post your entire code, only relevant code.

CSS transitions don't work well with display:none. When I had to use display:none, I had to use Javascript to supplement my CSS.

So, if you remove display:none from #bubble, and then use:

-webkit-transition:all 1000ms;

On #bubble, and then have #bubble:hover set to change the opacity to 1:

opacity:1;

Your bubble will fade in, and then fade out.

http://jsfiddle.net/charlescarver/nrTMg/1/

2
On

When you are using a transition you must have both "before" and "after" states set (e.g. you cant transition from nothing to opacity:0 but you can from opacity:1 to opacity:0). Also, you can't have a transition on display but you can on visibility.

Here's some more about transitions: https://developer.mozilla.org/en-US/docs/CSS/Tutorials/Using_CSS_transitions