jquery - 内联 block 内的 CSS 绝对子项导致布局错误

标签 jquery html css

对于我的生活,我无法弄清楚为什么会这样......任何人都可以在这个 jsfiddle 中看到为什么如果你将鼠标悬停在百叶窗元素上,其他两个会下降吗?

http://jsfiddle.net/vBR23/

jQuery(window).load(function(){
    jQuery('#topMenu li.has-children > a').each(function() {
        jQuery(this).parent().data('width', jQuery(this).innerWidth() + 14);
    });

    jQuery('#topMenu li.has-children').hover(function() {
        jQuery(this).css({ width: jQuery(this).data('width') + 'px' });
        jQuery(this).children('a').css({
            background: '#fff',
            left: '0',
            padding: '0 7px',
            position: 'absolute',
            top: '0',
            zIndex: '2'
        });
    }, function() {
        jQuery(this).css({ width: 'auto' });
        jQuery(this).children('a').css({
            background: 'transparent',
            left: 'auto',
            padding: '0',
            position: 'relative',
            top: 'auto',
            zIndex: '2'
        });
    });
});

我已经尝试尽可能地从它提取的元素中剥离它,但基本上我正在做的是当您将鼠标悬停在 li 上时,在绝对和相对定位之间切换内部“a”。在我看来,无论内容如何,​​li 都应该彼此并排呈现......它们都是相对位置且具有定义的高度。

似乎发生在 FF、Chrome 和 Opera 中。我还没有尝试过 IE。

谢谢。

最佳答案

vertical-align:top 添加到li 标签。 http://jsfiddle.net/vBR23/1/

关于jquery - 内联 block 内的 CSS 绝对子项导致布局错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24935033/

相关文章:

html - Wp电子商务下一页的当前菜单项不显示

jquery - 为什么我不能从元素中删除内联样式

jquery - 在 JQuery 中处理 F5

javascript - Bootstrap Collapse show.bs.collapse 第二次不工作

html - 使用表格对齐图像

javascript - 无法更改按键上的 CSS 属性值

javascript - 为什么 JavaScript 中的函数 element.style.height 可能不起作用?

javascript - 在 setTimeout 内创建 setTimeout 以停止

JQuery 读取 JSON(全局/局部变量)

html - 解析/显示 HTML 中的 RTF 文本?