对象已移动

可在此处找到该文档 How to Use the Double Ampersand Selector in Sass [Article] – New Self New Life
New Self New Life
No Result
View All Result
  • Home
  • Entertainment
  • Celebrity
  • Cinema
  • Music
  • Digital Lifestyle
  • Social Media
  • Softwares
  • Devices
  • Home
  • Entertainment
  • Celebrity
  • Cinema
  • Music
  • Digital Lifestyle
  • Social Media
  • Softwares
  • Devices
New Self New Life
No Result
View All Result
Home Softwares

How to Use the Double Ampersand Selector in Sass [Article]

by admin
3 years ago
in Softwares
How to Use the Double Ampersand Selector in Sass [Article]
Share on FacebookShare on Twitter


The Sass ampersand (&) image is used to reference the mum or dad selector in a nested rule. For instance, the next targets .btn on :hover:

.btn {
  ...
  &:hover {
    background: dodgerblue;
  }
}

We will additionally place the & after a selector to reverse the nesting order:

.btn {
  ...
  .navbar & {
    background: lightsteelblue;
  }
}

This outputs a descendant selector that targets a .btn aspect inside .navbar:

.btn {
  ...
}
.navbar .btn {
  background: lightsteelblue;
}

We will take this idea a step additional with an adjoining sibling combinator.

The Sass Ampersand & the Adjoining Sibling Selector

The adjoining sibling combinator (+) is used to focus on a component’s instant sibling. As an illustration:

.heading + .intro {
  ...
}

This targets any intro class instantly following a component with the category heading. Let’s check out two helpful methods we are able to use this combinator with the & selector.

Adjoining Buttons

Let’s say now we have a button group consisting of a major and a secondary motion button. Each have the category btn.

<div class="btn-group">
  <a category="btn" href="#">Main Motion</a>
  <a category="btn" href="#">Secondary Motion</a>
</div>

The secondary motion button must be a special coloration and have a left margin to separate it from its sibling. We will use the next rule to reference btn, then goal its instant sibling with the identical class:

.btn {
  ...
  & + & {
    margin-left: 15px;
    background: firebrick;
  }
}

If two btn lessons are adjoining siblings, the second will get the firebrick background and left margin. Right here’s the CSS output:

.btn {
  ...
}
.btn + .btn {
  margin-left: 15px;
  background: firebrick;
}

See CodePen Demo

Columns

The adjoining & selector additionally helps with column structure. To create a row the place all however the first column have a left margin (or gutter), we are able to write the next:

.col {
  ...
  & + & {
    margin-left: 30px;
  }
}

The primary column will stay flush with the left facet of the web page, whereas the others get a roomy left margin.

See CodePen Demo

As we simply realized, the “double Sass ampersand” sibling selector is a useful resolution that retains us from writing additional CSS and lessons in our markup. Strategies like these are a number of the some ways Sass helps us write cleaner, extra environment friendly front-end code.

Study Extra Concerning the Sass Ampersand & Different Sass Fundamentals with Treehouse

Treehouse gives a variety of programs and Techdegrees that you should use to enhance your Sass abilities. Study extra about utilizing the Sass ampersand and different Sass fundamentals by signing up for a free trial of Treehouse at the moment!



Source link

Tags: AmpersandArticleDoubleSassSelector
Previous Post

Hackers compromised Okta’s private GitHub repos

Next Post

YouTube Adds New Shorts Insights and Post Presentation Options

Related Posts

New tool offers direct lighting control for photographs using 3D scene modeling
Softwares

New tool offers direct lighting control for photographs using 3D scene modeling

by admin
August 3, 2025
Laravel ONDC Connector – Webkul Blog
Softwares

Laravel ONDC Connector – Webkul Blog

by admin
August 2, 2025
The hidden crisis behind AI’s promise: Why data quality became an afterthought
Softwares

The hidden crisis behind AI’s promise: Why data quality became an afterthought

by admin
July 31, 2025
Lazarus Group hackers increase open-source weaponisation
Softwares

Lazarus Group hackers increase open-source weaponisation

by admin
July 30, 2025
The Worst Career Advice Right Now: “Don’t Learn to Code” [Article]
Softwares

The Worst Career Advice Right Now: “Don’t Learn to Code” [Article]

by admin
August 1, 2025
Next Post
YouTube Adds New Shorts Insights and Post Presentation Options

YouTube Adds New Shorts Insights and Post Presentation Options

Twitter Adds New Qualification Process for Community Notes to Improve Note Value

Twitter Adds New Qualification Process for Community Notes to Improve Note Value

  • Trending
  • Comments
  • Latest
Instagram Adds New Teleprompter Tool To Edits

Instagram Adds New Teleprompter Tool To Edits

June 11, 2025
Critics And Fans Disagree On Netflix’s Controversial Fantasy Show With Near-Perfect RT Score

Critics And Fans Disagree On Netflix’s Controversial Fantasy Show With Near-Perfect RT Score

July 5, 2025
The hidden crisis behind AI’s promise: Why data quality became an afterthought

The hidden crisis behind AI’s promise: Why data quality became an afterthought

July 31, 2025
TikTok Publishes Report on Top UK Product Trends

TikTok Publishes Report on Top UK Product Trends

August 3, 2025
I Tried Calocurb For 90 Days. Here’s My Review.

I Tried Calocurb For 90 Days. Here’s My Review.

January 8, 2025
Abbotsford, B.C., denies permit for MAGA singer

Abbotsford, B.C., denies permit for MAGA singer

August 2, 2025
Spotify Stock Dips On Q2 Earnings Miss, Focus On Ads Business

Spotify Stock Dips On Q2 Earnings Miss, Focus On Ads Business

July 29, 2025
Ultra-Mini Qi2 Magnetic Power Bank with Kickstand from Baseus is now available on Amazon

Ultra-Mini Qi2 Magnetic Power Bank with Kickstand from Baseus is now available on Amazon

July 30, 2025
Liam Neeson, Pamela Anderson Get Nod From Natasha Richardson’s Sister

Liam Neeson, Pamela Anderson Get Nod From Natasha Richardson’s Sister

August 4, 2025
How Much Money the Late Actress Made – Hollywood Life

How Much Money the Late Actress Made – Hollywood Life

August 4, 2025
Photos + Review — My Chemical Romance Bring the Heat in Arlington

Photos + Review — My Chemical Romance Bring the Heat in Arlington

August 3, 2025
Chris Meloni Teases Law & Order: SVU Appearance: ‘Hangin With Friends’

Chris Meloni Teases Law & Order: SVU Appearance: ‘Hangin With Friends’

August 3, 2025
Awesome JAWS Poster Art From Artist Tyler Stout Pays Tribute To Quint — GeekTyrant

Awesome JAWS Poster Art From Artist Tyler Stout Pays Tribute To Quint — GeekTyrant

August 3, 2025
Epson Pro Cinema LS9000: Affordable 4K 120Hz Laser Projector For Gaming And Home Theater

Epson Pro Cinema LS9000: Affordable 4K 120Hz Laser Projector For Gaming And Home Theater

August 3, 2025
Donald Trump Responds to Question About Pardoning Diddy

Donald Trump Responds to Question About Pardoning Diddy

August 2, 2025
A Timeline of the Sex and the City Feud Between Kim Cattrall and Sarah Jessica Parker

A Timeline of the Sex and the City Feud Between Kim Cattrall and Sarah Jessica Parker

August 3, 2025
New Self New Life

Your source for entertainment news, celebrities, celebrity news, and Music, Cinema, Digital Lifestyle and Social Media and More !

Categories

  • Celebrity
  • Cinema
  • Devices
  • Digital Lifestyle
  • Entertainment
  • Music
  • Social Media
  • Softwares
  • Uncategorized

Recent Posts

  • Liam Neeson, Pamela Anderson Get Nod From Natasha Richardson’s Sister
  • How Much Money the Late Actress Made – Hollywood Life
  • Photos + Review — My Chemical Romance Bring the Heat in Arlington
  • Home
  • Disclaimer
  • DMCA
  • Privacy Policy
  • Cookie Privacy Policy
  • Terms and Conditions
  • Contact us

Copyright © 2021 New Self New Life.
New Self New Life is not responsible for the content of external sites. slotsfree  creator solana token

No Result
View All Result
  • Home
  • Entertainment
  • Celebrity
  • Cinema
  • Music
  • Digital Lifestyle
  • Social Media
  • Softwares
  • Devices

Copyright © 2021 New Self New Life.
New Self New Life is not responsible for the content of external sites.

New Self New Life