CSS 菜单导航

发布于 2024-11-28 19:07:36 字数 1099 浏览 5 评论 0原文

我无法理解这些代码的含义 -

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 技术交流群。

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

发布评论

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

评论(3

沒落の蓅哖 2024-12-05 19:07:36

1) .main ul ul 指的是:

<div class="main">
    <ul>
        <li>
            **<ul>** ... **</ul>**
            **<ul>** ... **</ul>**
        </li>
    </ul>
    ...
</div>

2) .main ul li:hover ul ul 指的是以下内容,仅当鼠标位于第一级

  • 上时(用 1 个星号标记) ,请注意这个
      比上一个示例更深一层
  • <div class="main">
        <ul>
            *<li>*
                <ul>
                    <li>
                        **<ul>**...**</ul>**
                        **<ul>**...**</ul>**
                    </li> 
                </ul>
                <ul> ... </ul>
            *</li>*
        </ul>
        ...
    </div>
    

    3) .main ul li:hover ul 指的是**

      ** 当鼠标悬停在 *

    • * 上时
    <div class="main">
        <ul>
            *<li>*
                **<ul>**
                    .
                    .
                    . 
                **</ul>**
                **<ul>** ... **</ul>**
            *</li>*
        </ul>
        ...
    </div>
    

    4) .main ul ul li:hover ul 指的是 **

      ** 当您的鼠标悬停在最后一个示例中的 *

    • * 上时,请注意更深层次的
    • 代码>现在是响应鼠标的焦点:
    <div class="main">
        <ul>
            <li>
                <ul>
                    *<li>*
                        **<ul>**...**</ul>**
                        **<ul>**...**</ul>**
                    *</li> *
                </ul>
                <ul> ... </ul>
            </li>
        </ul>
        ...
    </div>
    

    1) .main ul ul refers to:

    <div class="main">
        <ul>
            <li>
                **<ul>** ... **</ul>**
                **<ul>** ... **</ul>**
            </li>
        </ul>
        ...
    </div>
    

    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 example

    <div class="main">
        <ul>
            *<li>*
                <ul>
                    <li>
                        **<ul>**...**</ul>**
                        **<ul>**...**</ul>**
                    </li> 
                </ul>
                <ul> ... </ul>
            *</li>*
        </ul>
        ...
    </div>
    

    3) .main ul li:hover ul refers to the **<ul>** when your mouse is over the *<li>*

    <div class="main">
        <ul>
            *<li>*
                **<ul>**
                    .
                    .
                    . 
                **</ul>**
                **<ul>** ... **</ul>**
            *</li>*
        </ul>
        ...
    </div>
    

    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:

    <div class="main">
        <ul>
            <li>
                <ul>
                    *<li>*
                        **<ul>**...**</ul>**
                        **<ul>**...**</ul>**
                    *</li> *
                </ul>
                <ul> ... </ul>
            </li>
        </ul>
        ...
    </div>
    
    趴在窗边数星星i 2024-12-05 19:07:36

    编辑:感谢您编辑您的原始帖子 - 我将尝试回答您的更多问题:

    问题:

    如果有 2 个 ul,我们只需使用“.main ul ul”&然后在下一行我们
    使用悬停。但是如果不将鼠标悬停在上面,我们如何获得 2 个 ul?

    您想知道为什么仅在第二个无序列表 (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:

    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?

    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).

    小嗲 2024-12-05 19:07:36

    步步。让我们首先检查一下

      .main ul ul, .main ul li:hover ul ul {display: none;}
    

    它的作用,它隐藏了所有嵌套列表。请注意,可能存在这样的东西:

    <ul id="first">
     <li>
      <ul id="second">
       <li>
         <ul id="third">
            ...
    

    “第三”列表也满足“ul ul”。你能看到,“第三”在“第二”里面吗?这并不重要,这是在开头。它是与您输入的内容相同,

      div{ ... }
    

    它将适用于每个 div,无论它是否位于任何其他元素内,

      div div{ ... } would apply to all elements in such structure:
    
     <any number of any tags>
      <div>
       <optional any number of any tags>
        <div class="applied">
          <div class="applied">
            ....
             <div class="applied">
    

    这很简单。
    现在,.main ul li:hover ul ul 遵循相同的模式,但它从 li:hover 开始计数。假设您有 5 级菜单,并将鼠标悬停在第三级内。那么这个公式所做的就是简单地隐藏第五层。

    Step by step. Let's first examine

      .main ul ul, .main ul li:hover ul ul {display: none;}
    

    what it does, it hides all nested lists. Please be aware, that something like thisd" may exists:

    <ul id="first">
     <li>
      <ul id="second">
       <li>
         <ul id="third">
            ...
    

    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

      div{ ... }
    

    it will apply to every div, no matter if it is inside any other element.

      div div{ ... } would apply to all elements in such structure:
    
     <any number of any tags>
      <div>
       <optional any number of any tags>
        <div class="applied">
          <div class="applied">
            ....
             <div class="applied">
    

    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.

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