css - 动画工具提示淡入和淡出

标签 css

我怎样才能让这个工具提示随着淡入淡出而显示和隐藏?我尝试添加:

transition: opacity .25s ease-in-out;
-moz-transition: opacity .25s ease-in-out;
-webkit-transition: opacity .25s ease-in-out;

但运气不好,这是我的代码

工具提示 CSS:

.mainButtonContainer button:hover:after
{

    background: none repeat scroll 0 0 rgba(255, 255, 255, 0.7);
    border-color: #093466;
    border-radius: 5px 5px 5px 5px;
    border-style: solid;
    border-width: 7px 2px 2px;
    bottom: -5px;
    color: #093466;
    padding: 5px 15px;
    position: absolute;
    width: 113px;
    z-index: -1;
}

html:

<button  id=mgf_main1 type="button" onclick="loadData(1)">
    <img src="Images/Magof-Icon.png" width="68" height="68"/>
</button>

jsfiddle.net/rdRhS

最佳答案

您需要将描述元素的所有内容移至 button:after,并且仅更改 button:hover:after 中悬停时更改的属性。

fiddle

button:after {
    opacity: 0;

    -webkit-transition: opacity .25s ease-in-out;
       -moz-transition: opacity .25s ease-in-out;
            transition: opacity .25s ease-in-out;

    content:'';
    background: none repeat scroll 0 0 rgba(255, 255, 255, 0.7);
    border-color: #093466;
    border-radius: 5px 5px 5px 5px;
    border-style: solid;
    border-width: 7px 2px 2px;
    bottom: -5px;
    color: #093466;
    padding: 5px 15px;
    position: absolute;
    top:50px;
    left:70px;
    width: 113px;
    height: 30px;
    z-index: -1;
}

button:hover:after {
    opacity: 1;    
}

关于css - 动画工具提示淡入和淡出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18446988/

相关文章:

css - 使用CSS水平居中和间距

css - 未能在验证错误中应用样式

html - 在 div 中居中一些元素

html - li 被隐藏的问题,按钮向下太远

html - 第 n 个子选择器 css

css - 溢出 :hidden not working on mobile browser

html - 选择具有来自 div 的额外顶部填充

html - 导航栏上方的 div 看起来不像预期的那样

html - 导航栏未正确放置在包裹内,

php - 跨页面混合 PHP 和 CSS