first parent ul and first li doesn't work properly

user2109456

I have an issue when selecting the first ul and its first li but it affects the first li of the second ul>li too.

My attempt:

#main-nav ul:first-child li:first-child{
    border-radius:5px 0px 5px 0px;
}

The corresponding html:

<nav id="main-nav">
    <ul>
     <li><a href="#">Home</a></li>
     <li><a href="#">Blog</a></li>
         <li><a href="#">Photos</a>
           <ul>
             <li><a href="#">Gallery 1</a></li>
             <li><a href="#">Gallery 2</a></li>
           </ul>
         </li>
     <li><a href="#">About</a></li>
     <li><a href="#">Contacts</a></li>
    </ul>
  <div style="clear:both;"></div>
</nav>
Hidden Hobbes

I think what you are after is:

#main-nav ul:first-child > li:first-child {
   border-radius:5px 0px 5px 0px;
}

This will only select the first li of the first ul as > selects only child elements of the element preceding it.

As Paulie_D suggests, #main-nav > ul > li:first-child is a bit more concise and will also work as long as there is just the one child ul in #main-nav.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

toggleClass() doesn't work after first time

분류에서Dev

drawImage() doesn't work properly javascript

분류에서Dev

php editing script doesn't work properly

분류에서Dev

Node js require doesn't work properly

분류에서Dev

ExecuteScalar doesn't return the first column of the first row

분류에서Dev

Find first available value that doesn't exist

분류에서Dev

ul ul li first child를 모두 제거하지 않고 ul li first child를 제거하려면 어떻게해야합니까?

분류에서Dev

MongoDB find with $text index doesn't work properly

분류에서Dev

Theme for Code Block doesn't work properly in Confluence 5.1

분류에서Dev

Regex doesn't seem to work properly in my code

분류에서Dev

A method to convert ppm to ascii art doesn't work properly

분류에서Dev

XCode 7 auto-completion doesn't work properly

분류에서Dev

Button value doesn't change after first click

분류에서Dev

Bootstrap 3 modal doesn't close after first opening

분류에서Dev

android emulator doesn't display my first 'standard' helloWorld app

분류에서Dev

iOS: The written accent in the first character doesn't appear in an UILabel

분류에서Dev

Selecting first-child anchor element in an ul

분류에서Dev

My DLL doesn't work properly when it's placed on System's directory

분류에서Dev

Spring MVC, pattern doesn't work properly in case of forward slash symbol in path variable

분류에서Dev

CSS - modify parent based on first child

분류에서Dev

unbind doesn't work

분류에서Dev

Crontab doesn't work

분류에서Dev

Javascript does't work at first but works on second, third, etc. times

분류에서Dev

Javascript does't work at first but works on second, third, etc. times

분류에서Dev

Nested UIScrollView with pagingEnabled on the encompassing one doesn't receive the first bottom swipe after page change

분류에서Dev

bash listing subfolders in current folder doesn't give expected results [gives only first folder]

분류에서Dev

LinearLayout doesn't fill the parent

분류에서Dev

Change li font in ul?

분류에서Dev

Php break the ul li

Related 관련 기사

  1. 1

    toggleClass() doesn't work after first time

  2. 2

    drawImage() doesn't work properly javascript

  3. 3

    php editing script doesn't work properly

  4. 4

    Node js require doesn't work properly

  5. 5

    ExecuteScalar doesn't return the first column of the first row

  6. 6

    Find first available value that doesn't exist

  7. 7

    ul ul li first child를 모두 제거하지 않고 ul li first child를 제거하려면 어떻게해야합니까?

  8. 8

    MongoDB find with $text index doesn't work properly

  9. 9

    Theme for Code Block doesn't work properly in Confluence 5.1

  10. 10

    Regex doesn't seem to work properly in my code

  11. 11

    A method to convert ppm to ascii art doesn't work properly

  12. 12

    XCode 7 auto-completion doesn't work properly

  13. 13

    Button value doesn't change after first click

  14. 14

    Bootstrap 3 modal doesn't close after first opening

  15. 15

    android emulator doesn't display my first 'standard' helloWorld app

  16. 16

    iOS: The written accent in the first character doesn't appear in an UILabel

  17. 17

    Selecting first-child anchor element in an ul

  18. 18

    My DLL doesn't work properly when it's placed on System's directory

  19. 19

    Spring MVC, pattern doesn't work properly in case of forward slash symbol in path variable

  20. 20

    CSS - modify parent based on first child

  21. 21

    unbind doesn't work

  22. 22

    Crontab doesn't work

  23. 23

    Javascript does't work at first but works on second, third, etc. times

  24. 24

    Javascript does't work at first but works on second, third, etc. times

  25. 25

    Nested UIScrollView with pagingEnabled on the encompassing one doesn't receive the first bottom swipe after page change

  26. 26

    bash listing subfolders in current folder doesn't give expected results [gives only first folder]

  27. 27

    LinearLayout doesn't fill the parent

  28. 28

    Change li font in ul?

  29. 29

    Php break the ul li

뜨겁다태그

보관