css - 如何旋转:before pseudo element when parent is hovered

标签 css hover font-awesome pseudo-class

我已将字体图标添加到这样的列表中:

a:before {
    font-family: FontAwesome;
    content: "\f015";
    .. etc..
}

当父 anchor 标记悬停时,我希望这个 :before pseudo 被旋转。我试过这个,但它不起作用:

a:hover:before {
            -webkit-transform:rotate(360deg);
            -moz-transform:rotate(360deg);
            -o-transform:rotate(360deg);
}

这行不行?仅当父元素悬停时,我该怎么做才能在 :before 元素上获得旋转效果?

最佳答案

试试这个:

a:before {
    -webkit-transition: all 300ms 0s ease-in-out;
    transition: all 300ms 0s ease-in-out;

    content: "\f015";
    display: inline-block; //as @Rohit Azad suggested
    font-family: FontAwesome;

    // .. etc ..
}

a:hover:before {
    -webkit-transform: rotate(360deg);
    transform: rotate(360deg);
}

看看这个fiddle .

关于css - 如何旋转:before pseudo element when parent is hovered,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24553684/

相关文章:

CSS,悬停一个元素,影响另一个

css - 使用 CSS 旋转在相对层次结构中悬停不可靠

CSS :hover height change not working

html - 相同高度列 bootstrap 3 行响应

css - 如何将文字字符串注入(inject) scss @mixin

html - 为什么我看不到来 self 选择的链接的子菜单?

javascript - 如何将超赞字体添加到输入文本字段?

html - 显示内联 block 不适用于 col-xs-6 Bootstrap

css - 组合框 extjs 6 中显示的超赞字体图标

html - font-awesome ,当使用属性时图标消失