• <small id='UOYjd'></small><noframes id='UOYjd'>

      • <bdo id='UOYjd'></bdo><ul id='UOYjd'></ul>
      1. <legend id='UOYjd'><style id='UOYjd'><dir id='UOYjd'><q id='UOYjd'></q></dir></style></legend>
        <i id='UOYjd'><tr id='UOYjd'><dt id='UOYjd'><q id='UOYjd'><span id='UOYjd'><b id='UOYjd'><form id='UOYjd'><ins id='UOYjd'></ins><ul id='UOYjd'></ul><sub id='UOYjd'></sub></form><legend id='UOYjd'></legend><bdo id='UOYjd'><pre id='UOYjd'><center id='UOYjd'></center></pre></bdo></b><th id='UOYjd'></th></span></q></dt></tr></i><div id='UOYjd'><tfoot id='UOYjd'></tfoot><dl id='UOYjd'><fieldset id='UOYjd'></fieldset></dl></div>

        <tfoot id='UOYjd'></tfoot>

        悬停一个元素,然后更改另一个元素(不使用 Javascript)

        Hover one element, and change another (without using Javascript)(悬停一个元素,然后更改另一个元素(不使用 Javascript))

        <legend id='NitGd'><style id='NitGd'><dir id='NitGd'><q id='NitGd'></q></dir></style></legend>
          <tbody id='NitGd'></tbody>

        <small id='NitGd'></small><noframes id='NitGd'>

          <bdo id='NitGd'></bdo><ul id='NitGd'></ul>
          • <i id='NitGd'><tr id='NitGd'><dt id='NitGd'><q id='NitGd'><span id='NitGd'><b id='NitGd'><form id='NitGd'><ins id='NitGd'></ins><ul id='NitGd'></ul><sub id='NitGd'></sub></form><legend id='NitGd'></legend><bdo id='NitGd'><pre id='NitGd'><center id='NitGd'></center></pre></bdo></b><th id='NitGd'></th></span></q></dt></tr></i><div id='NitGd'><tfoot id='NitGd'></tfoot><dl id='NitGd'><fieldset id='NitGd'></fieldset></dl></div>
              <tfoot id='NitGd'></tfoot>

                  本文介绍了悬停一个元素,然后更改另一个元素(不使用 Javascript)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个嵌套的 CSS 菜单,我无法显示子菜单.

                  I have a nested CSS menu that I can't get the submenus to come up.

                  我从 一个列表分开获取代码.该站点上的示例运行良好,但由于我的页面上有 2 个 CSS 导航菜单,我必须将我的 HTML 元素放在不同的 CSS 类中.

                  I took the code from A list apart. The example on that site works perfectly fine, but since I have 2 CSS navigational menus on my page, I have to put my HTML elements in different CSS classes.

                  这是我的代码:

                  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" 
                  
                  "http://www.w3.org/TR/html4/strict.dtd">
                  <html>
                  <head>
                    <style type="text/css">
                      ul#lvl1 {
                          margin:0;
                          padding:0;
                          list-style:none;
                          width:150px; /* Width of Menu Items */
                          border-bottom:1px solid #ccc;
                      }
                      li.lvl1 {position:relative}
                      ul.lvl2 {
                          position: absolute;
                          left: 149px; /* Set 1px less than menu width */
                          top: 0;
                          display: none;
                      }
                      /* Styles for Menu Items */
                      li.lvl1 > a {
                        display: block;
                          text-decoration: none;
                          color: #777;
                          background: #fff; /* IE6 Bug */
                          padding: 5px;
                          border: 1px solid #ccc;
                          border-bottom: 0;
                      }
                      /* Fix IE. Hide from IE Mac */
                      *  html.lvl1 > ul > li {float:left;height:1%}
                      *  html.lvl1 > ul > li > a {height:1%}
                      /* End */
                      li.lvl2 > a:hover { color: #E2144A; background: #f9f9f9; } /* Hover Styles */
                      li.lvl2 > a { padding: 2px 5px; } /* Sub Menu Styles */
                      a.lvl1:hover ul.lvl2 {display: block} /* The magic */
                    </style>
                  </head>
                  <body>
                    <ul id="lvl1">
                      <li class="lvl1">
                        <a class="lvl1" href="#">item1</a>
                        <ul class="lvl2">
                          <li class="lvl2">
                            <a class="lvl2" href="#">subitem1</a>
                          </li>
                        </ul>
                      </li>
                      <li class="lvl1">
                        <a class="lvl1" href="#">item2</a>
                        <ul class="lvl2">
                          <li class="lvl2">
                            <a class="lvl2" href="#">subitem2</a>
                          </li>
                        </ul>
                      </li>
                    </ul>
                  </body>
                  </html>
                  

                  现在,当我将鼠标悬停在 1 级的a"上时,2 级的ul"不会出现.有人可以阐明一下吗?我可能遗漏了一些明显的东西.谢谢!

                  Now when I hover over the "a" on level 1, the "ul" on level 2 won't come up. Can someone please shed some light? I may be missing something obvious. Thanks!

                  推荐答案

                  你必须改变你的 CSS 选择器来定位 lvl2 <ul>,因为它不再嵌套(它是一个兄弟,所以使用 +).

                  You must change your CSS selector to target the lvl2 <ul>, since it is not nested anymore (it's a sibling, so use +).

                  a.lvl1:hover + ul.lvl2 {display: block} /* The magic */
                  

                  你应该阅读这个css 选择器列表.

                  或者您可以将鼠标悬停在 lvl1 <li> 上,而不是锚点

                  Or you could move the hover on the lvl1 <li>, instead of the anchor

                  li.lvl1:hover ul.lvl2 {display: block} /* The magic */
                  

                  这篇关于悬停一个元素,然后更改另一个元素(不使用 Javascript)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Move link image 5px up on hover(悬停时将链接图像向上移动 5px)
                  How do I inspect CSS pseudo classes with firebug?(如何使用 firebug 检查 CSS 伪类?)
                  Why doesn#39;t CSS hover work on table rows when the cells inside the rows have class names?(当行内的单元格具有类名时,为什么 CSS 悬停在表格行上不起作用?)
                  Hover image - display div over it(悬停图像 - 在其上显示 div)
                  How to apply a CSS class on hover to dynamically generated submit buttons?(如何在悬停时将 CSS 类应用于动态生成的提交按钮?)
                  Differences between CSS3 :hover and :focus?(CSS3 :hover 和 :focus 的区别?)
                    <bdo id='OKSMp'></bdo><ul id='OKSMp'></ul>
                      <tbody id='OKSMp'></tbody>

                    <legend id='OKSMp'><style id='OKSMp'><dir id='OKSMp'><q id='OKSMp'></q></dir></style></legend>

                    <small id='OKSMp'></small><noframes id='OKSMp'>

                    <tfoot id='OKSMp'></tfoot>

                          <i id='OKSMp'><tr id='OKSMp'><dt id='OKSMp'><q id='OKSMp'><span id='OKSMp'><b id='OKSMp'><form id='OKSMp'><ins id='OKSMp'></ins><ul id='OKSMp'></ul><sub id='OKSMp'></sub></form><legend id='OKSMp'></legend><bdo id='OKSMp'><pre id='OKSMp'><center id='OKSMp'></center></pre></bdo></b><th id='OKSMp'></th></span></q></dt></tr></i><div id='OKSMp'><tfoot id='OKSMp'></tfoot><dl id='OKSMp'><fieldset id='OKSMp'></fieldset></dl></div>