YogeshChauhan . com

Selector Lists and Combinators in SCSS (Sass)

in SCSS on April 25, 2021

We know about basic nesting in SCSS (SassScript) but there is so much more than just basic nesting.

Selector Lists

Selector lists are nothing but comma-separated selectors. If you want to apply same nesting rule for more than one selectors, SCSS gives you an easy way to do it.

Just like this:

Each selector in the list is nested separately and then combined into a selector list.

Here’s the compiled CSS:


.alert ul, .alert p, .warning ul, .warning p {
    border: 1px solid white;
}

Selector Combinators

We can use nesting for the selectors that use combinators.

Just like this:

Here’s the compiled CSS:


ul > li {
  list-style-type: none;
}

h2 + p {
  border-top: 1px solid gray;
}

p ~ span {
  opacity: 0.8;
}

dreamhost

Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #3 How to uninstall Cocoapods from the Mac OS? #4 How to add Read More Read Less Button using JavaScript? #5 How to Use SQL MAX() Function with Dates? #6 PHP Login System using PDO Part 1: Create User Registration Page

Recently Posted

May 5 Use inline if to make a shorter conditional syntax in React May 4 What is Conditional Rendering in React? May 3 How does @extend rule work in SCSS (Sass)? May 2 How different is Handling Events in React vs HTML DOM? May 2 How to create bouncing balls using HTML canvas and JavaScript? Apr 30 HTML canvas methods

You might also like these

CSS align-items property examplesCSSWhat happened to your Google Analytics Tracking ID, can’t find it?MiscWhat does it mean by Continuous Integration, Continuous Delivery and Continuous Deployment?MiscSolution for Xcode 11 Command PhaseScriptExecution failed with a nonzero exit code errorMiscHow to get category name using post id in WordPress?WordPressHow to send and receive query strings via links in Angular 9?AngularJavaScript String fromCharCode() MethodJavaScriptData Flows in ReactReactHow to show confirmation alerts with OK and cancel buttons using Swift 5?SwiftLEFT JOIN in PostgresPostgresHow to use HTML picture Tag?HTMLperspective property in CSSCSS