Image hover transition for span

<a href=""><img src=""><span>content</span></a>

Here,When i am hovering on an image, the span content appears by using position relative to display none and position absolute in the span tag. Now, my question is, when i am hovering on an image, i need transition effect. For that, what is the css. Please help me.


You cannot transit an element having display: none; to display: block; so for that you need to use opacity property...

Fails

Passes

Better Demo In Action

.example1 {
    border: 1px solid #f00;
    height: 30px;
}

.example1 span {
    opacity: 0;
    -webkit-transition: all 1s;
    -moz-transition: all 1s;
    transition: all 1s;
}

.example1:hover span {
    opacity: 1;
}

One alternative for trying to transition between display:none , and display:block

is to transition instead between visibility: hidden; and visibility:visible

See this article which states:

visibility animates despite the CSS Basic Box Model spec saying “Animatable: no”


a.tip2 {
  position: relative;
  text-decoration: none;
}
a.tip2 span {display: none;
     opacity: 0;
    -webkit-transition: all 1s;
    -moz-transition: all 1s;
    transition: all 1s;
}
a.tip2:hover span {
  display: block;
  position: absolute; 
  padding: .5em;
  content: attr(title);
  min-width: 120px;
  text-align: center;
  width: 162px;
    height:auto;    
  top: -247px;
left: 70px;
  background: rgba(0,0,0,.8);
  -moz-border-radius:10px;
  -webkit-border-radius:10px;
  border-radius:10px;    
  color: #fff;
  font-size: .86em;
opacity: 1;
}
a.tip2:hover span:after {
  position: absolute;
  display: block;
  content: "";  
  border-color: rgba(0,0,0,.8) transparent transparent transparent;
  border-style: solid;
  border-width: 10px;
  height:0;
  width:0;
  position:absolute;
  bottom: -16px;
  left:1em;
}

This is my css and actually i forget to say one thing. This is an tool tip using pure css.

链接地址: http://www.djcxy.com/p/83658.html

上一篇: HTML / CSS弹出窗口显示不响应

下一篇: 跨度的图像悬停过渡