webkit-transition,使用width时的异常:auto

Ram*_*oup 9 css webkit css-transitions

我有标准<ul><li><a></a></li></ul>模式的侧边栏导航,使用溢出隐藏截断链接的全文.在悬停1秒后,我希望锚点在宽度上展开,显示链接的全文.

我有这个功能完全在CSS中工作,但我遇到了异常:我将锚的宽度设置为Auto on:hover.触发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;
    }       
Run Code Online (Sandbox Code Playgroud)

Pau*_*ish 21

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

一般情况下过渡到auto还没有工作.我喜欢在这些情况下使用最小宽度和最大宽度来近似效果.


cem*_*egr 6

在特定宽度和自动之间切换的解决方案:获得宽度的唯一方法:自动; 过渡到可靠地工作是使用Javascript显式设置项目的宽度.我知道这会破坏使用CSS转换的目的,但这是我如何使它工作:

$(".author").each(function() {
  $(this).width( $(this).width() );
});
Run Code Online (Sandbox Code Playgroud)

然后在css

.author:hover { width: 200px; !important }
Run Code Online (Sandbox Code Playgroud)

编辑:这是一个纯粹的CSS解决方案,用于在0和auto之间切换:CSS转换不适用于百分比高度?