9

我有一个标准<ul><li><a></a></li></ul>模式的侧边栏导航,它使用溢出隐藏截断链接的全文。悬停 1s 后,我希望锚点扩大宽度,显示链接的全文。

我有这个功能完全在 CSS 中工作,但我遇到了异常:我将锚点的宽度设置为 Auto on :hover。触发 1s 延迟后,anchor 的宽度会捕捉到 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;
    }       
4

2 回答 2

21

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

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

于 2011-07-19T18:49:36.683 回答
6

在特定宽度和自动之间切换的解决方案:获取宽度的唯一方法:自动;可靠工作的过渡是使用 Javascript 显式设置项目的宽度。我知道这违背了使用 CSS 过渡的目的,但这是我如何让它工作的:

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

然后在css中

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

编辑:这是用于在 0 和自动之间切换的纯 CSS 解决方案:CSS 过渡不适用于百分比高度?

于 2012-01-25T00:19:25.677 回答