CSS | element element Selector

The element element selector in CSS is used to select elements inside the elements i.e it combines two selectors such that elements matched by the second selector are selected if they have an ancestor element matching the first selector.

Syntax:

element element {
    // CSS Property
}

Example 1:



filter_none

edit
close

play_arrow

link
brightness_4
code

<!-- HTML code to illustrates space selector -->
<!DOCTYPE html>
<html>
    <head>
        <title>
            element element Selector
        </title>
          
        <style>
            div p {
                background-color: green;
                color: white;
            }
        </style>
    </head>
      
    <body style="text-align: center;">
          
        <h1 style = "color: green;">
            GeeksforGeeks
        </h1>
          
        <div>
            <h2>element element Selector</h2>
              
            <!-- CSS property is used here -->
            <p>A computer science portal for geeks.</p>
        </div>
          
        <p>This paragraph will not be selected.</p>
    </body>
</html>                    

chevron_right


Output:
element_element

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
    <head>
        <title>
            element element Selector
        </title>
          
        <style>
            li {
                color: black;
            }         
            li li {
                color: white;
                background: green;
            }
        </style>
    </head>
      
    <body style="text-align: center;">
          
        <h1 style = "color: green;">
            GeeksforGeeks
        </h1>
          
        <h2>element element Selector</h2>
        <ul>
            <li>
                <div>Searching Algo</div>
                <ul>
                    <li>Binary Search</li>
                    <li>Linear Search</li>
                </ul>
            </li>
            <li>
                <div>Sorting Algo</div>
                <ul>
                    <li>Bubble Sort</li>
                    <li>Merge Sort</li>
                </ul>
            </li>
        </ul>
    </body>
</html>                    

chevron_right


Output:
element_element2

Supported Browsers: The browser supported by element element selector are listed below:

  • Apple Safari
  • Google Chrome
  • Firefox
  • Opera
  • Internet Explorer


My Personal Notes arrow_drop_up


If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.