对象已移动

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

Microsoft announces preview of its new Agent Framework
Softwares

Microsoft announces preview of its new Agent Framework

by admin
October 2, 2025
Graffiti framework lets people personalize online social spaces while staying connected with others
Softwares

Graffiti framework lets people personalize online social spaces while staying connected with others

by admin
October 5, 2025
Epic Games Store iOS installs soar as DMA pressures Apple in EU
Softwares

Epic Games Store iOS installs soar as DMA pressures Apple in EU

by admin
October 1, 2025
Configure New Relic for Magento 2 Project
Softwares

Configure New Relic for Magento 2 Project

by admin
October 4, 2025
What is Parameter-Efficient Fine-Tuning (PEFT) and Why It Matters
Softwares

What is Parameter-Efficient Fine-Tuning (PEFT) and Why It Matters

by admin
September 29, 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
I Only Have More Questions After Another Bizarre Outing With The Harrigans

I Only Have More Questions After Another Bizarre Outing With The Harrigans

April 20, 2025
Amazon Forgot to Take the 2024 MacBook Air Off Sale After Their Big Spring Event

Amazon Forgot to Take the 2024 MacBook Air Off Sale After Their Big Spring Event

April 4, 2025
Ecca Vandal’s “CRUISING TO SELF SOOTHE” video is an ode to skate culture

Ecca Vandal’s “CRUISING TO SELF SOOTHE” video is an ode to skate culture

March 10, 2025
Easy Blueberry Scones (With Frozen Blueberries)

Easy Blueberry Scones (With Frozen Blueberries)

April 10, 2025
A Global Recognition of Indi

A Global Recognition of Indi

April 21, 2025
Tuesday Snapshot – Vivaldi Browser snapshot 3621.3

Tuesday Snapshot – Vivaldi Browser snapshot 3621.3

March 5, 2025
I finally watched The Truman Show

I finally watched The Truman Show

April 6, 2025
Mar 7, 2025: 10 AI updates from the past week

Mar 7, 2025: 10 AI updates from the past week

March 9, 2025
BYD Surpasses Tesla As Global EV Leader

BYD Surpasses Tesla As Global EV Leader

October 5, 2025
NFL Week 5 Football Games: Dates, Where to Watch and More (Oct. 5-6)

NFL Week 5 Football Games: Dates, Where to Watch and More (Oct. 5-6)

October 5, 2025
50 Cent Being So Stoked At His Taylor Swift Shoutout Is EVERYTHING! And Travis Kelce Thought So Too!

50 Cent Being So Stoked At His Taylor Swift Shoutout Is EVERYTHING! And Travis Kelce Thought So Too!

October 5, 2025
‘The Batman II’ Should Be Out This Weekend. Why Do We Care?

‘The Batman II’ Should Be Out This Weekend. Why Do We Care?

October 4, 2025
The ‘Magic Trick’ Lady Gaga Learned From Bruce Springsteen

The ‘Magic Trick’ Lady Gaga Learned From Bruce Springsteen

October 4, 2025
24 Bizarre Celeb Facts That Sound Fake, But Are 100% True

24 Bizarre Celeb Facts That Sound Fake, But Are 100% True

October 4, 2025
What to Expect Based on Last Year

What to Expect Based on Last Year

October 4, 2025
How Many Years He Will Be in Prison – Hollywood Life

How Many Years He Will Be in Prison – Hollywood Life

October 4, 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

  • BYD Surpasses Tesla As Global EV Leader
  • NFL Week 5 Football Games: Dates, Where to Watch and More (Oct. 5-6)
  • 50 Cent Being So Stoked At His Taylor Swift Shoutout Is EVERYTHING! And Travis Kelce Thought So Too!
  • 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