html - Chrome 中伪元素的 CSS 过渡

标签 html css webkit

如何使 CSS 过渡在伪元素上起作用?

示例:

<div class="foo" data-foo='baz'>bar</div>
<div>hover below for the working (non-pseudo) effect</div>
<div class="tar" data-foo='arrr'>nyan</div>

样式:

.foo {
    margin: 20px;
    padding: 6px;
    background-color: #fcc;
}

.foo:after {
    margin-left: 4px;
    content: 'hoot';
    font-weight: bold;
    opacity: 0;
    -webkit-transition: opacity 1s ease;
}

.foo:hover:after {
    opacity: 1;
}




.tar {
    margin: 20px;
    padding: 6px;
    background-color: #fcc;
}

.tar {
    margin-left: 4px;
    content: 'hoot';
    font-weight: bold;
    opacity: 0;
    -webkit-transition: opacity 1s ease;
}

.tar:hover {
    opacity: 1;
}

fiddle :

http://jsfiddle.net/sdzUp/1/

这似乎只适用于 firefox(具有适当的前缀)

最佳答案

你可以这样试试

HTML

<div class="foo" data-foo='baz'>bar <font>hoot</font></div>
<div>hover below for the working (non-pseudo) effect</div>
<div class="tar" data-foo='arrr'>nyan</div>

CSS

.foo {
    margin: 20px;
    padding: 6px;
    background-color: #fcc;
    -webkit-transition: all 1s ease;
    -moz-transition: all 1s ease;
    transition: all 1s ease;
}
.foo font{
    font-weight: bold;
    opacity: 0;
    -webkit-transition: opacity 1s ease;
    -moz-transition: all 1s ease;
    transition: all 1s ease;
}
.foo:hover font{
    opacity: 1;
}
.foo:hover:after {
    opacity: 1;
}
.tar {
    margin: 20px;
    padding: 6px;
    background-color: #fcc;
}
.tar {
    margin-left: 4px;
    content: 'hoot';
    font-weight: bold;
    opacity: 0;
    -webkit-transition: opacity 1s ease;
    -moz-transition: opacity 1s ease;
    transition: opacity 1s ease;
}
.tar:hover {
    opacity: 1;
}

演示:http://jsfiddle.net/enve/sdzUp/5/

关于html - Chrome 中伪元素的 CSS 过渡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14800691/

相关文章:

css - 在另一个下面制作 float 框

html - IE10 字体大小缩小了 1px。怎么修?

css - ie6 错误,文本在 div 中被裁剪

javascript - 如何在webkit中获取多列布局中的列数

html - 想要 HTML 按钮发送带有输入详细信息的电子邮件

jQuery:根据鼠标位置移动的全屏 "background"图像

javascript - 元素可见后触发的事件

javascript - 如何在 WebKit 中获取所有受支持的 CSS 属性?

css - 什么列轴 : vertical; does?

html - 如何摆脱这条线?