get first child css code example

Example 1: css not first child

.block:not(:first-child) {
    background-color: #990000;
}

//if you need to support legacy browsers then follow the below solution

.block {
    background-color: #990000;  /* applies to every ul */
}

.block:first-child {
    background-color: transparent; /* limits the scope of the previous rule */
}

Example 2: css first child

:first-child {
	//styles here
}

:nth-child(1) { //the benefit of this is you can do it for 2nd, 3rd etc...
	//styles here 
}

Example 3: css first

:first-of-type {
	//styles here
}

:first-child {
	//styles here
}

:nth-child(1) { //the benefit of this is you can do it for 2nd, 3rd etc...
	//styles here 
}

Example 4: css first child

/*CSS First - forth child*/
:first-child {}

:nth-child(2){}
:nth-child(3){}
:nth-child(4){}

Example 5: first-child

p:first-child {
  background-color: yellow;
}

Example 6: select first child in element css

p:first-child
 { 

   background-color: yellow;

 }

Tags:

Css Example