鼠标悬停时带有飞出子菜单的垂直菜单

发布于 2024-11-27 09:05:17 字数 3187 浏览 1 评论 0原文

我正在尝试创建一个带有弹出窗口的垂直菜单。这是一个带有子菜单的垂直菜单。以下代码有什么问题吗?

<html>
    <head>
        <title>Untitled Document</title>
        <style type="text/css">
            #navmenu ul ul li a {
                border:1px solid #888888; border-bottom: none; font-size:12pt; line-height: 1.6em; color:#303030; background-color:#a5a5a5; background-image:none;
            }
            #navmenu {
                width: 150px; /* set width of menu */
            }  
            #navmenu ul {
                list-style-type:none; margin:0px;   padding:0px;
            }
            #navmenu a {
                text-decoration:none; border: 1px solid #303030; width:170px;   display:block;   text-align:center;   font-size:14pt;   line-height:2em; background:url(Button_top.gif) repeat-x left;   font-family:Arial, Helvetica, sans-serif; color:white;
            }
            #navmenu a:hover {
                color: #a00;
                /* red text color on hover */
                background: #fff;
                /* white bgcolor on hover */
            }
            #navmenu li {
                /* make the list elements a containing block for the nested lists */
                position: relative;
            }
            #navmenu ul ul {
                position: absolute; top: 0; left: 100%;
                /* to position them to the right of their containing block */
                width: 100%;
                /* width is based on the containing block */
                }  
            #navmenu li {
                /* make the list elements a containing block for the nested lists */
                position: relative;
            }
            #navmenu ul ul {
                display: none;
            }
            #navmenu ul li:hover ul {
                display:block;
            }
        </style>
    </head>
    <body>
        <div id="navmenu">
            <ul>
                <li>
                    <a href="#">Home</a>
                </li>
                <li>
                    <a href="#">Blog</a>
                </li>
                <ul>
                    <li>
                        <a href="#">Blog 1</a>
                    </li>
                    <li>
                        <a href="#">Blog 2</a>
                    </li>
                </ul>
                <li>
                    <a href="#">Websites</a>
                </li>
                <ul>
                    <li>
                        <a href="#">Websites 1</a>
                    </li>
                    <li>
                        <a href="#">Websites 2</a>
                    </li>
                </ul>
                <li>
                    <a href="#">Photos</a>
                </li>
            </ul>
        </div>
    </body>
</html>

http://jsfiddle.net/9bHkj/1/

I am trying to create a vertical menu with fly outs .That is a vertical menu with sub-menus.What is wrong with the following code?

<html>
    <head>
        <title>Untitled Document</title>
        <style type="text/css">
            #navmenu ul ul li a {
                border:1px solid #888888; border-bottom: none; font-size:12pt; line-height: 1.6em; color:#303030; background-color:#a5a5a5; background-image:none;
            }
            #navmenu {
                width: 150px; /* set width of menu */
            }  
            #navmenu ul {
                list-style-type:none; margin:0px;   padding:0px;
            }
            #navmenu a {
                text-decoration:none; border: 1px solid #303030; width:170px;   display:block;   text-align:center;   font-size:14pt;   line-height:2em; background:url(Button_top.gif) repeat-x left;   font-family:Arial, Helvetica, sans-serif; color:white;
            }
            #navmenu a:hover {
                color: #a00;
                /* red text color on hover */
                background: #fff;
                /* white bgcolor on hover */
            }
            #navmenu li {
                /* make the list elements a containing block for the nested lists */
                position: relative;
            }
            #navmenu ul ul {
                position: absolute; top: 0; left: 100%;
                /* to position them to the right of their containing block */
                width: 100%;
                /* width is based on the containing block */
                }  
            #navmenu li {
                /* make the list elements a containing block for the nested lists */
                position: relative;
            }
            #navmenu ul ul {
                display: none;
            }
            #navmenu ul li:hover ul {
                display:block;
            }
        </style>
    </head>
    <body>
        <div id="navmenu">
            <ul>
                <li>
                    <a href="#">Home</a>
                </li>
                <li>
                    <a href="#">Blog</a>
                </li>
                <ul>
                    <li>
                        <a href="#">Blog 1</a>
                    </li>
                    <li>
                        <a href="#">Blog 2</a>
                    </li>
                </ul>
                <li>
                    <a href="#">Websites</a>
                </li>
                <ul>
                    <li>
                        <a href="#">Websites 1</a>
                    </li>
                    <li>
                        <a href="#">Websites 2</a>
                    </li>
                </ul>
                <li>
                    <a href="#">Photos</a>
                </li>
            </ul>
        </div>
    </body>
</html>

http://jsfiddle.net/9bHkj/1/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情归归情 2024-12-04 09:05:17

您可能需要重新审视构建菜单的方式。例如:

            <li>
                <a href="#">Blog</a>
            </li>
            <ul>
                <li>
                    <a href="#">Blog 1</a>
                </li>
                <li>
                    <a href="#">Blog 2</a>
                </li>
            </ul>

应该是一个 Blog 菜单,有两个子菜单 Blog 1Blog 2。但是子菜单的

    应该位于菜单的

  • 内,而不是单独的:
   <li>
      <a href="#">Blog</a>
      <!-- The <li> does not end here -->
      <ul>
         <li>
            <a href="#">Blog 1</a>
         </li>
         <li>
            <a href="#">Blog 2</a>
         </li>
      </ul>
   </li>  <!-- end tag for the blog <li>, now enclosing the submenu also -->

一旦您执行此操作,对于其他子菜单,您也将拥有飞行子菜单。您现在可以确定位置、颜色等。

You might have to revisit how you are constructing the menu. For instance:

            <li>
                <a href="#">Blog</a>
            </li>
            <ul>
                <li>
                    <a href="#">Blog 1</a>
                </li>
                <li>
                    <a href="#">Blog 2</a>
                </li>
            </ul>

is supposed to be a Blog menu with two sub menus Blog 1 and Blog 2. But then <ul> for the sub menu is supposed to be within the <li> of the menu and not separately:

   <li>
      <a href="#">Blog</a>
      <!-- The <li> does not end here -->
      <ul>
         <li>
            <a href="#">Blog 1</a>
         </li>
         <li>
            <a href="#">Blog 2</a>
         </li>
      </ul>
   </li>  <!-- end tag for the blog <li>, now enclosing the submenu also -->

Once you do this, for the other submenus as well, you have the flying sub menus. You can now work out the location, colors etc.

段念尘 2024-12-04 09:05:17

你写了两次:

#navmenu li {
    /* make the list elements a containing block for the nested lists */
    position: relative;
}

你的嵌套列表ul不包含在li元素中。因此,这也不起作用:

#navmenu ul li:hover ul {
    display:block;
}

ul 嵌套在 li 元素中可能可以解决您的问题。

you wrote this twice:

#navmenu li {
    /* make the list elements a containing block for the nested lists */
    position: relative;
}

Your nested lists ul are not contained by li elements. So this will not work either:

#navmenu ul li:hover ul {
    display:block;
}

nesting your ul in li elements may solve your problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文