nav ul li ul and nav>ul>li in CSS style

Keywords: Attribute

Question: What is the difference between nav ul li ul and NAV > UL > Li in CSS style? What is the function of ">", thank you.

    <style>
        *{
            margin:0;
            padding:0;
            list-style:none;
        }

        nav ul li ul{
            display:none;
        }

        nav>ul>li{
            float:left;
            padding:10px;
            border:1px solid blue;
        }

        nav>ul>li>ul>li{
            padding:10px;
            border-bottom:1px solid #ccc;
        }
    </style>

Look at all four answers

The answer is helpful and valuable to people. 0 The answer is not helpful. It's the wrong answer.

> It means only one generation after another, such as NAV > UL > Li > UL > li. It must be the following.

            <nav>
                <ul>
                    <li>
                        <ul>
                            <li></li>
                        </ul>
                    </li>
                </ul>
            </nav>

Then nav ul li ul only requires the following elements to be in the order under the nav tag, and is insensitive to several layers of mid-distance, such as:

            <nav>
                <div>
                    <ul>
                        <div>
                            <a>
                                <li>
                                    <div>
                                        <ul>
                                            <li>
                                            </li>
                                        </ul>
                                    </div>
                                </li>
                            </a>
                        </div>
                    </ul>
                </div>
            </nav>

Recommended answers

The answer is helpful and valuable to people. 4 The answer is not helpful. It's the wrong answer.
<nav>
    <ul id="a">
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li>
            <ul id="b">
                <li></li><li></li>
            </ul>
        </li>
        <li>
            <ul id="c">
                <li></li><li></li>
            </ul>
        </li>
    </ul>
</nav>

NAV > ul only selects ul elements in the next level of nav, such as ul with id a in the dom structure above.
nav ul selects all ul elements contained in nav, such as all ul elements whose id is a, b, c in the dom structure above.

Nav>ul ratio nav ul is more stringent, and the elements that follow must be only one level lower than those that precede.

Posted by Lucky_PHP_MAN on Tue, 12 Feb 2019 18:15:19 -0800