简体   繁体   English

悬停时的宽度表现有趣吗?

[英]Width on hover acting funny?

If you take a look at this page: http://wearewebstars.dk/frontend/Test/boerneunivers2.html Then clicking on ex: third link in the left navigation, then you will see that that link is now the current - Then if you hover over the fourth link, then the width in the third link changes? 如果您查看此页面: http : //wearewebstars.dk/frontend/Test/boerneunivers2.html,然后单击左侧导航中的ex:第三个链接,那么您将看到该链接现在是当前链接-如果您将鼠标悬停在第四个链接上,然后第三个链接的宽度会发生变化吗? Cant figure out why? 无法弄清楚为什么? Any help will be greatly appreciated... 任何帮助将不胜感激...

I've used jquery to the hover effekt, like this: 我已经将jquery用于悬停效果,如下所示:

$(".left-navigation ul li:not(.current)").hover(function( e ){

     var mEnt = e.type=="mouseenter"; // boolean true/false

     $(this).stop().animate({width: mEnt?'100%':35}, mEnt?100:0, function() {
         $(this).find("span.nav-text").css({
             display: mEnt? "inline-block" : "none"
         });
     });

});

The width of the <li> becomes 100%. <li>的宽度变为100%。 The width of the <ul> is dependent of the .left-navigation . <ul>的宽度取决于.left-navigation Since that width isn't set, it as wide as the content. 由于未设置该宽度,因此它与内容一样宽。 Because the <li> of the hover is bigger than the active one, the ul grows. 因为悬停的<li>大于活动悬停的<li> ,所以ul会增长。

Simple fix: 简单修复:

.left-navigation {
    width: 200px
}

I can't tell you the exact problem, because I think your navigation should not work at all. 我无法告诉您确切的问题,因为我认为您的导航根本不起作用。

But your problem is with the % width of the li elements in the current/hover state. 但是您的问题是在当前/悬停状态下li元素的%宽度。

The percent width has the meaning the given percentage of the parents width is used of the element. width百分比的含义是使用元素的给定父width百分比。 Because the ul is growing for certain elements in its width , the current element also growth in its width . 因为ul在其width某些元素上在增长,所以当前元素在其width也在增长。

Why the hover works with percentage in the initial stage is not clear to me right now, I would need to look closer at it. 现在我尚不清楚为什么悬停在初始阶段可以按百分比工作,所以我需要仔细研究一下。 But hopefully this information already helps you. 但是希望这些信息已经对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM