Loading Please Wait...

Logo Lynxsia IT Solutions

CSS Combinator Selectors

CSS Combinator Selectors

Combinator selectors selects element based on the relationship between elements.

  • Descendant Combinators
  • Child Combinators
  • General Sibling Combinators
  • Adjacent Sibling Combinators
  • Column Combinators
Descendant Combinators

Descendant combinator selectors selects all the elements that are descendant of first selector. It is defined by the space (" ").

Here descendant element can be an child, sub child, and so on in the DOM tree.

Syntax: selector1 selector2

Let's see with some example
					 
        
          /* All list items inside <ul> element having navigation class */
          /* Also select nested list items */
          ul.navigation li{
            color: green;
          }

          /* All heading class elements inside section class element. */
          .section .heading{
            color: green;
          }

          /* All content class inside body class inside container class. */
          .container .body .content{
            color: green;
          }
        
      
Child Combinators

Child combinator selectors selects all the elements that are direct children of the first selector. It is defined by the > symbol.

Syntax: selector1 > selector2

Let's see with some example
					 
        
          /* All list item inside <ul> element having navigation class */
          /* Do not select nested list items */
          ul.navigation > li{
            color: green;
          }

          /* All heading class elements inside section class element. */
          .section > .heading{
            color: green;
          }

          /* All content class inside body class inside container class. */
          .container > .body > .content{
            color: green;
          }
        
      
General Sibling Combinators

General sibling combinator selectors selects all the elements that are sibling of the first selector. Second element must comes after the first element (Not necessarily immediately) and both shares the same parent. Previous siblings are not selected. It is defined by the ~ symbol.

Syntax: selector1 ~ selector2

Let's see with some example
					 
        
          /* All paragraph followed by heading */
          /* Also select paragraph if there is another element between them */
          /* Paragraphs before heading are not selected */
          h1 ~ p{
            color: green;
          }

          /* All subheading class after heading. */
          .heading ~ .subheading{
            color: green;
          }

          /* All body class after container class. */
          .container ~ .body{
            color: green;
          }
        
      
Adjacent Sibling Combinators

Adjacent sibling combinator selectors selects all the elements that are direct sibling of the first selector. Second element must comes immediate after the first element and both shares the same parent. It is defined by the + symbol.

Syntax: selector1 + selector2

Let's see with some example
					 
        
          /* All paragraph just after heading */
          h1 + p{
            color: green;
          }

          /* All subheading just after heading. */
          .heading + .subheading{
            color: green;
          }

          /* All body just after container class. */
          .container + .body{
            color: green;
          }
        
      
Column Combinators

Column combinator selectors selects all the elements which belongs to a column. It is defined by the || symbol. Check browser compatibility before use. Element must be a column element such as <table> element.

Syntax: selector1 || selector2

Let's see with some example
					 
        
          /* All td cell where col is defined as active */
          col.active || td{
            color: green;
          }
        
      

How you feel about this blog:

Share this blog on:

Report Us

If you find any error in the turtorials, or want to share your suggestion/feedback, feel free to send us email at: info@lynxsia.com

Contact Us
Ads
Logo
Lynxsia IT Solutions

We are concern with various development process like website design & development, E-commerce development, Software development, Application development, SMS & Bulk SMS Provider, PWA Development, and many more..

Kotwali Road, Chhiptehri, Banda, 210001, UP, India

Copyright © 2022, Lynxsia IT Solutions, All rights reserved