Yogesh Chauhan's Blog

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;
}


Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 How to add Read More Read Less Button using JavaScript? #3 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #4 Solution to the error “Visual Studio Code can’t be opened because Apple cannot check it for malicious software” #5 How to uninstall Cocoapods from the Mac OS? #6 PHP Login System using PDO Part 1: Create User Registration Page

Recently Posted

#Apr 8 JSON.stringify() in JavaScript #Apr 7 Middleware in NextJS #Jan 17 4 advanced ways to search Colleague #Jan 16 Colleague UI Basics: The Search Area #Jan 16 Colleague UI Basics: The Context Area #Jan 16 Colleague UI Basics: Accessing the user interface
You might also like these
Can We Use For Loop to Loop Through Associative Arrays in PHP?PHPHow to add a ribbon inside a container using CSS?CSSPostgreSQL BETWEENPostgresHow to deploy Angular App on Dreamhost or Amazon S3 or firebase?AngularThe SQL UNION OperatorSQL/MySQLWhat is the difference between float and double?MiscellaneousA Quick Guide to Object-Oriented Programming in PHPPHPSolution for “Yarn build: Failed because of a stylelint error”WordPressThe basics of @import rule in SCSS (Sass)SCSSHow to Recognize an Array in JavaScript?JavaScriptThe SQL EXISTS OperatorSQL/MySQLSolution to “Call to undefined function mysql_error()” in RevSlider WordPress PluginWordPress