DEV Community

Rupak Dey
Rupak Dey

Posted on Edited on

CSS Combinator Selectors

.abc.xyz

Chained Class Selector : will select elements that have both class names.

.nav__item.selected {
   color : #fff;
}
🏆 ยอดนิยม: deyrupak/css combinator selectors aa - ประเด็นร้อน 🏆 ยอดนิยม: deyrupak/css combinator selectors aa - ประเด็นร้อน

.abc .xyz

Descendant Selector : will select all matching elements inside parent element.

.div img {
   width : 100%;
}
🏆 ยอดนิยม: deyrupak/css combinator selectors aa - ประเด็นร้อน 🏆 ยอดนิยม: deyrupak/css combinator selectors aa - ประเด็นร้อน

.abc > .xyz

Direct Descendant Selector : will select only direct children of the parent and ignore elements that are nested further.

.nav > .li {
   font-size : 2rem;
}
🏆 ยอดนิยม: deyrupak/css combinator selectors aa - ประเด็นร้อน 🏆 ยอดนิยม: deyrupak/css combinator selectors aa - ประเด็นร้อน


.abc + .xyz

Adjacent Sibling Selector : will select first element immediately preceded by the former element.

.list-item + .list-item {
   color : #3254a8;
}
🏆 ยอดนิยม: deyrupak/css combinator selectors aa - ประเด็นร้อน 🏆 ยอดนิยม: deyrupak/css combinator selectors aa - ประเด็นร้อน

.abc ~ .xyz

General Sibling Selector : will select all sibling elements on the same level.

.container ~ p {
   font-size : 2rem;
}
🏆 ยอดนิยม: deyrupak/css combinator selectors aa - ประเด็นร้อน 🏆 ยอดนิยม: deyrupak/css combinator selectors aa - ประเด็นร้อน


Save it. Its time to show your CSS skills!



Connect with me : Github | Tutoring | Freelance Web Dev

Top comments (6)

🏆 ยอดนิยม: deyrupak/css combinator selectors aa - ประเด็นร้อน
 
amankanojiya profile image
AMANKANOJIYA •

.container ~ p {
font-size : 2rem;
}
Sir, I do not understand. Can you pls Give me an Example

🏆 ยอดนิยม: deyrupak/css combinator selectors aa - ประเด็นร้อน
 
sir_zel profile image
Ilja • • Edited

here you go

🏆 ยอดนิยม: deyrupak/css combinator selectors aa - ประเด็นร้อน
 
deyrupak profile image
Rupak Dey •

Thank You! :D

🏆 ยอดนิยม: deyrupak/css combinator selectors aa - ประเด็นร้อน
 
amankanojiya profile image
AMANKANOJIYA •

Thank you So much, sir. It will help me a lot. I got it as it will grab all elements from the container in which ~ is defined

🏆 ยอดนิยม: deyrupak/css combinator selectors aa - ประเด็นร้อน
 
deyrupak profile image
Rupak Dey •

That's a great example by @sir_zellot there!

🏆 ยอดนิยม: deyrupak/css combinator selectors aa - ประเด็นร้อน
 
amankanojiya profile image
AMANKANOJIYA •

yes, Sir, I got it