对象已移动

可在此处找到该文档 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

Minor update(4) for Vivaldi Android Browser 7.4
Softwares

Minor update(4) for Vivaldi Android Browser 7.4

by admin
June 21, 2025
How AI Medical Coding Software Reduces Errors & Accelerates Billing in 2025
Softwares

How AI Medical Coding Software Reduces Errors & Accelerates Billing in 2025

by admin
June 22, 2025
10+ Best Free Portfolio & Lookbook Templates for InDesign in 2025 — Speckyboy
Softwares

10+ Best Free Portfolio & Lookbook Templates for InDesign in 2025 — Speckyboy

by admin
June 20, 2025
User Guide For CS-Cart Product Search By Barcode
Softwares

User Guide For CS-Cart Product Search By Barcode

by admin
June 18, 2025
Open Talent platforms emerging to match skilled workers to needs, study finds
Softwares

Open Talent platforms emerging to match skilled workers to needs, study finds

by admin
June 16, 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
Pamela Anderson raves about new natural, makeup-free look: ‘It’s freedom’

Pamela Anderson raves about new natural, makeup-free look: ‘It’s freedom’

October 8, 2023
Alec Baldwin indicted again for ‘Rust’ shooting that left cinematographer dead – National

Alec Baldwin indicted again for ‘Rust’ shooting that left cinematographer dead – National

January 21, 2024
I Tried Calocurb For 90 Days. Here’s My Review.

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

January 8, 2025
Guide for Bagisto Quick Commerce

Guide for Bagisto Quick Commerce

October 16, 2024
A look into CAMPUS, ShopBack’s new Singapore HQ at Pasir Panjang

A look into CAMPUS, ShopBack’s new Singapore HQ at Pasir Panjang

July 2, 2022
8BitDo Retro Mechanical Keyboard C64 Review

8BitDo Retro Mechanical Keyboard C64 Review

March 24, 2025
Bones: All Of Brennan’s Interns, Ranked

Bones: All Of Brennan’s Interns, Ranked

June 15, 2021
Gabby Logan shares emotional family update in rare post with daughter Lois

Gabby Logan shares emotional family update in rare post with daughter Lois

September 25, 2024
Shane Gillis Set As Host Of The 2025 ESPYS For ABC & ESPN+

Shane Gillis Set As Host Of The 2025 ESPYS For ABC & ESPN+

June 24, 2025
Cobra Kai star Martin Kove ‘kicked out of fan convention’ after allegedly ‘biting’ co-star Alicia Hannah-Kim

Cobra Kai star Martin Kove ‘kicked out of fan convention’ after allegedly ‘biting’ co-star Alicia Hannah-Kim

June 24, 2025
Liam Neeson Drives a Bus to Escape Himalayan Kidnappers in Trailer For ICE ROAD: VENGEANCE — GeekTyrant

Liam Neeson Drives a Bus to Escape Himalayan Kidnappers in Trailer For ICE ROAD: VENGEANCE — GeekTyrant

June 24, 2025
Maroon 5’s New Album ‘Love Is Like’ Release Date, Tour Dates Announced

Maroon 5’s New Album ‘Love Is Like’ Release Date, Tour Dates Announced

June 23, 2025
Google adds AI features to Chromebook Plus devices

Google adds AI features to Chromebook Plus devices

June 23, 2025
Generations: The Legacy Teasers on SABC1 June

Generations: The Legacy Teasers on SABC1 June

June 23, 2025
‘Elio’ Had Pixar’s Worst Box Office Opening Weekend Ever

‘Elio’ Had Pixar’s Worst Box Office Opening Weekend Ever

June 23, 2025
Love Island Season 7 Recap: Week 3 Twists Amid Casa Amor (Updating Daily)

Love Island Season 7 Recap: Week 3 Twists Amid Casa Amor (Updating Daily)

June 23, 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

  • Shane Gillis Set As Host Of The 2025 ESPYS For ABC & ESPN+
  • Cobra Kai star Martin Kove ‘kicked out of fan convention’ after allegedly ‘biting’ co-star Alicia Hannah-Kim
  • Liam Neeson Drives a Bus to Escape Himalayan Kidnappers in Trailer For ICE ROAD: VENGEANCE — GeekTyrant
  • 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