【问题标题】:CSS transition width on :after element:after 元素上的 CSS 过渡宽度
【发布时间】:2013-06-08 22:26:13
【问题描述】:

我在转换此元素中的 with opening 时遇到了一些问题。这是fiddle

#control:after{
    content:"R";
    background-color:#333;
    color:#fff;
    display:inline-block;
    line-height:20px;
    padding:10px;
    height:20px;
    font-weight:bold;
    -webkit-transition: width 2s linear;
    -moz-transition: width 2s linear;
    -ms-transition: width 2s linear;
    -o-transition: width 2s linear;
    transition: width 2s linear;
    font-family:helvetica
}

#control:hover:after{
    content: "REGGI";
    width:auto;
    cursor:pointer;
}

【问题讨论】:

标签: css css-transitions


【解决方案1】:

我在没有他的情况下完成了 CSS http://jsfiddle.net/vveST/

a{
    text-decoration:none
}

#control{
    background-color:#333;
    color:#fff;
    display:inline-block;
    line-height:20px;
    padding:10px 15px;
    height:20px;
    width:12px;
    font-weight:bold;
    font-family:helvetica;
    -webkit-transition: width 0.1s ease;
    -moz-transition: width 0.1s ease;
    -ms-transition: width 0.1s ease;
    -o-transition: width 0.1s ease;
    transition: width 0.1s ease;
}

#control .b{
    display:none;
}

#control:hover .a{
    display:none;
}

#control:hover .b{
    display:inline-block;
}

#control:hover{
    width:55px;
    cursor:pointer;
}

【讨论】:

    【解决方案2】:

    WebKit 中有一个长期存在的错误,即无法转换伪元素,但现在已修复,我认为这不是问题所在。

    这里的问题是你不能转换到auto 值。您需要使用绝对值。

    您还必须设置一个初始值:

    #control:after{
        content:"R";
        background-color:#333;
        color:#fff;
        display:inline-block;
        line-height:20px;
        padding:10px;
        height:20px;
        font-weight:bold;
        -webkit-transition: width 2s linear;
        -moz-transition: width 2s linear;
        -ms-transition: width 2s linear;
        -o-transition: width 2s linear;
        transition: width 2s linear;
        font-family:helvetica
    
        width: 50px;
    }
    
    #control:hover:after{
        content: "REGGI";
        width: 100px;
        cursor:pointer;
    }
    

    【讨论】:

    • 您是否尝试过使用静态值而不是自动值?因为我是的,但它仍然无法正常工作:jsfiddle.net/Vvscq/1627
    • 你用的是什么浏览器?
    • 我的铬。是的,我检查了其他,它在 FF 上工作,但你告诉 ...it is now fixed 是错误的 -.-
    • @WooCaSh 它在 WebKit 中已修复,该修复是否已进入 Chrome 是另一回事。
    • 我认为您可能还必须设置一个初始值。我用那个代码更新了我的答案。
    猜你喜欢
    • 2015-11-29
    • 1970-01-01
    • 2015-05-06
    • 2012-04-05
    • 2013-12-27
    • 2014-06-11
    • 1970-01-01
    • 1970-01-01
    • 2011-09-29
    相关资源
    最近更新 更多