Webkit-transition,使用width:auto时出现异常



我有一个标准<ul><li><a></a></li></ul>模式的侧边栏导航,它使用溢出隐藏截断链接的全文。在悬停15秒后,我想让锚扩展宽度,显示链接的全文。

我有这个功能在CSS中完全工作,但我遇到了异常:我有锚的宽度设置为自动:悬停。在触发1s延迟后,锚的宽度变为0,然后扩展到它的全宽度。

下面是我的css,在这里你可以看到我当前的代码:http://eventfeedstl.com/day/07182011/

.day .sidebar{
    width: 200px;   
    }
.day .sidebar ul {
    list-style: none;
    padding: 0;
    margin:0;
    position: absolute;
    width: auto;
    }
.day .sidebar ul li{
    border-bottom: 1px solid #626666;
    display: relative;
    width: 200px;
        }
.day .sidebar ul li:hover{
    width: auto;
        }
.day .sidebar ul li a{
    font-weight: normal;
    font-size: .8em;
    color: #f2f2f2;
    display: block;
    width: auto;
    padding: 4px 5px;
    background: none;
    width: 190px;
    height: 10px;
    overflow: hidden;
    position: relative;
    z-index: 10;
    -webkit-transition: background 1.3s ease-out;
    -moz-transition: background 1.3s ease-out;
        transition: background-color 1.3s ease-out; 
        }
.day .sidebar ul li a:hover {
    background: #797979;
    -webkit-transition: background 0.15s;
    -moz-transition: background 0.15s;
        transition: background 0.15s;
        text-decoration: none;
    width: auto;
       -webkit-transition-property:width;
       -webkit-transition-delay:1s;
        position: relative;
    }       

您正在覆盖背景和宽度之间的过渡,这可能会导致问题。有一种方法可以设置多个过渡,但我很确定这种方法会导致问题。

,

一般来说,过渡到auto还不起作用。在这些情况下,我喜欢使用min-width和max-width来近似效果。

在特定宽度和自动之间切换的解决方案:获取width的唯一方法:auto;要使transition可靠地工作,必须使用Javascript显式地设置条目的宽度。我知道这违背了使用CSS过渡的目的,但我是这样做的:

$(".author").each(function() {
  $(this).width( $(this).width() );
});

然后在css

.author:hover { width: 200px; !important }

编辑:这是一个纯CSS解决方案之间切换0和auto: CSS过渡不工作的百分比高度?

最新更新