CSS 菜单导航
我无法理解这些代码的含义 -
1) .main ul ul,
2) .main ul li:悬停 ul ul
3) .main ul li:hover ul
4) .main ul ul li:hover ul
这些代码用于隐藏或显示菜单&子菜单。熟悉 CSS 的人都知道这些代码。我想了很多,但无法清楚地理解! 这是因为上面的代码是以这种方式应用的 -
.main ul ul,
.main ul li:hover ul ul
{display: none;}
再说一遍 -
.main ul li:hover ul,
.main ul ul li:hover ul
{display:block;}
我的问题是,如果有 2 个 ul,我们只需使用“.main ul ul”&然后在下一行我们使用悬停。
但是如果不将鼠标悬停在上面,我们如何才能获得 2 个 ul 呢? 我的意思是第一行应该是 ul:hover ul,不是吗?
另外,如果前两行(即- .main ul ul, .main ul li:hover ul ul ) 用于 display:none ,那么为什么相同的两行不用于 display:block ???因为它们应该暗示相同的子菜单?
这里 .main 是一个像这样的 div 类 -
<div class="main">
<ul>
<li>..</li>
<li>..</li>
<li>..</li>
<ul>
<li>sub-menu1</li>
<li>sub-menu2</li>
.
.
.
</ul> etc etc...
<div>
实际上这是一种带有子菜单的垂直列表菜单。 希望你们都能明白我的意思。简单来说,我的问题是这个问题开头的前 4 行代码是什么意思? 请详细解释。 提前致谢
I cannot understand what this codes means -
1) .main ul ul,
2) .main ul li:hover ul ul
3) .main ul li:hover ul
4) .main ul ul li:hover ul
These codes are applied to hide or display menus & sub-menus .Those who are aware of CSS knows well of these codes. I thought much but cannot clearly understand!!
This is because the above codes are applied in this way-
.main ul ul,
.main ul li:hover ul ul
{display: none;}
Then again -
.main ul li:hover ul,
.main ul ul li:hover ul
{display:block;}
My question is,in case of 2 ul's we just use ".main ul ul" & then in the next line we use hover.
But without hovering over how can we get 2 ul's?
I mean it should be ul:hover ul in the first line,isn't it?
Also if the first 2 lines(i.e.- .main ul ul,
.main ul li:hover ul ul )are used for display:none ,then why the same 2 lines are not used for display:block???Because they should imply the same submenus?
Here .main is a div class like this-
<div class="main">
<ul>
<li>..</li>
<li>..</li>
<li>..</li>
<ul>
<li>sub-menu1</li>
<li>sub-menu2</li>
.
.
.
</ul> etc etc...
<div>
Actually this is a type of vertical list menu with submenus.
Hope you all get me.In simple words, my question what does the first 4 code lines at the very beginning of this question means?
Pls explain in details.
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
1) .main ul ul 指的是:
2) .main ul li:hover ul ul 指的是以下内容,仅当鼠标位于第一级
上时(用 1 个星号标记) ,请注意这个
比上一个示例更深一层
3) .main ul li:hover ul 指的是
**
**
当鼠标悬停在*
*
上时4) .main ul ul li:hover ul 指的是
**
**
当您的鼠标悬停在最后一个示例中的*
*
上时,请注意更深层次的1) .main ul ul refers to:
2) .main ul li:hover ul ul refers to the following, ONLY when the mouse is over the first level
<li>
(marked with 1 asterick), notice how this<ul>
is another level deeper form the last example3) .main ul li:hover ul refers to the
**<ul>**
when your mouse is over the*<li>*
4) .main ul ul li:hover ul refers to the
**<ul>**
when your mouse is over the*<li>*
in this last example, notice how a level deeper<li>
is now the responding to afocus of your mouse:编辑:感谢您编辑您的原始帖子 - 我将尝试回答您的更多问题:
问题:
您想知道为什么仅在第二个无序列表 (UL) 上调用悬停属性,以及如何在第一个无序列表上没有悬停属性的情况下显示第二个 ul。答案是这些无序列表默认是可见的。因此,它们都会在页面加载时显示。悬停属性只是告诉您的页面当用户将鼠标悬停在第二个列表上时如何反应。
我不完全确定你的问题以及它在问什么。如果您想了解每个 CSS 属性的用途,我可以帮助您解释。您的 DIV 容器的类名称为
.main
。1)
.main ul ul
- 这正在调用另一个无序列表中的无序列表,该无序列表是“.main”类的一部分。2)
.main ul li:hover
- 这是调用第一个无序列表中的一个列表项的悬停属性。因此,基本上每一顶行都引用不同的项目或项目中的不同属性(全部在
.main
DIV 内)。Edit: Thank you for editing your original post - I will try to answer a few more of your questions:
Question:
You want to know why the hover property is being called only on the second unordered list (UL), and how the second ul can even be displayed without the hover property being on the first ul. The answer is that these unordered lists are visible by default. Therefore, they will both be displayed when the page is loaded. The hover property just tells your page how to react when the user hovers over the second list.
I'm not completey sure of your queustion, and what it's asking. If you would like to know about what each CSS property is doing I can help to explain that. Your DIV container has a class name of
.main
.1)
.main ul ul
- this is calling what seems to be an unordered list inside of another unordered list which is part of the ".main" class.2)
.main ul li:hover
- This is calling the hover property of one of the list items within the first unordered list.So, basically each of the top lines is referring to either a different item, or a different property within an item (all within the
.main
DIV).步步。让我们首先检查一下
它的作用,它隐藏了所有嵌套列表。请注意,可能存在这样的东西:
“第三”列表也满足“ul ul”。你能看到,“第三”在“第二”里面吗?这并不重要,这是在开头。它是与您输入的内容相同,
它将适用于每个 div,无论它是否位于任何其他元素内,
这很简单。
现在,.main ul li:hover ul ul 遵循相同的模式,但它从 li:hover 开始计数。假设您有 5 级菜单,并将鼠标悬停在第三级内。那么这个公式所做的就是简单地隐藏第五层。
Step by step. Let's first examine
what it does, it hides all nested lists. Please be aware, that something like thisd" may exists:
the "third" list also satisfies "ul ul". Can you see, that "third" is inside "second" ? it does not matter this is in the beginning. It is the same as you type
it will apply to every div, no matter if it is inside any other element.
Ok that was easy.
Now, .main ul li:hover ul ul follows the same pattern, but it starts counting from li:hover. Imagine you have 5 level menu and you hover li inside third level. Then what this formula does is simple hiding the fifth level.