html - 如何在顶部对齐子菜单

标签 html css menu

我有一个菜单(黄色)和一个子菜单(第一列)和另一个子菜单。

我需要知道如何使子菜单始终位于顶部。

img

// menu in the middle
.leftMenu ul li .pchild {
    width: 193px;
    list-style: disc!important;
}
// child menu ( on the right )
    .leftMenu ul li .pchild li .childpost {
    padding-left: 20px;
    display: none;
    position: absolute;
    top: 0px;
    left: 175px;
    width: 413px;
}

为了简单起见:这是网站:http://www.ruigrok-nederland.nl/

最佳答案

它目前这样显示是因为它是相对于 li 元素的。您需要使其相对于 div.child 元素或类似元素。

对于您的代码,将 position:static 添加到您的 .leftMenu ul li .pchild li。像这样:

.leftMenu ul li .pchild li {
    position:static
}

也就是说,在 style.css140 行。

更新:

对于评论中的第二个问题,您将有两个选择:

  • 使用 jQuery 插件,如 hoverIntent 或众多在所有平台上都非常有用的菜单插件之一
  • 这样写你的CSS:

添加这个新样式:

.leftMenu ul li div.post{
    position: absolute;
    top: 0px;
    left: 175px;
    z-index: 10;
    width: 413px;
    height: 100%;
    display: none;
}

.leftMenu ul li .pchild li:hover .post {
    display: block;
}

删除:

padding-left: 20px;
display: none;
position: absolute;

.leftMenu ul li .pchild li:hover .childpost {
    display: block;
}

来自 .leftMenu ul li .pchild li .childpost

像这样在 .leftMenu .child 上更改您的 padding

padding: 0 24px 0 0!important;

关于html - 如何在顶部对齐子菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23433239/

相关文章:

html - 在不牺牲布局的情况下允许子菜单大于其父菜单?

javascript - 将菜单树代码从 jquery 1.7.1 迁移到 1.9.1

javascript - 比较两个字符串并显示字符串中不匹配单词的数量

javascript - 如果将所有网页资源都编译成一个 HTML 文件,加载速度会更快吗?

html - 图像宽度的 W3C 验证错误

javascript - 模拟拖放文件事件

css - Modernizr 无法正常工作(在 IE8 中应用字体类)

html - 如何将 wordpress 主题菜单搜索 .svg 图标更改为自定义 png

javascript - 在下拉菜单的 li 元素旁边显示 div

jquery - div 相对于另一个元素的位置