Ampersand

Patient Tools

Read, save, and share this guide

Use these quick tools to make this medical article easier to read, print, save, or share with a family member.

Article Summary

First a re-cap of the basic CSS Chain/Descendant Selector 1> Chain Selectors - https://stackoverflow.com/questions/13444647/css-class-definition-with-multiple-identifiers .class1.class2 will match only the elements that have both of the classes defined. .class1.class2 { background: red; } <div class="class1 class2"></div> 2> Descendant Selector The descendant selector matches all elements that are descendants of a specified element. And the Per Official doc .class1 .class2 { background: red; } 3> Child Selector The child...

Key Takeaways

  • This article explains css class definition with multiple identifiers in a single line – Understaning how it works in simple medical language.
  • This article explains 1> Chain Selectors - in simple medical language.
Educational health guideWritten for patient understanding and clinical awareness.
Reviewed content workflowUse writer and reviewer profiles for stronger trust.
Emergency safety firstUrgent warning signs are highlighted below.

Seek urgent medical care if you notice

These warning signs are general safety guidance. Local emergency numbers and clinical judgment should always come first.

  • Severe symptoms, breathing difficulty, fainting, confusion, or rapidly worsening illness.
  • New weakness, severe pain, high fever, or symptoms after a serious injury.
  • Any symptom that feels urgent, unusual, or unsafe for the patient.
1

Emergency now

Use emergency care for severe, sudden, rapidly worsening, or life-threatening symptoms.

2

See a doctor

Book a professional medical evaluation if symptoms persist, worsen, recur often, affect daily activities, or occur in a high-risk patient.

3

Learn safely

Use this article to understand possible causes, tests, treatment options, prevention, and questions to ask your clinician.

First a re-cap of the basic CSS Chain/Descendant Selector

1> Chain Selectors –

https://stackoverflow.com/questions/13444647/css-class-definition-with-multiple-identifiers

.class1.class2 will match only the elements that have both of the classes defined.

.class1.class2 { background: red; }

<div class="class1 class2"></div>

2> Descendant Selector

The descendant selector matches all elements that are descendants of a specified element.

And the Per Official doc

.class1 .class2 { background: red; }

3> Child Selector

The child selector selects all elements that are the children of a specified element.

The following example selects all

elements that are children of a

element:

div > p {
    background-color: yellow;
}

The meaning of a selector with more classes depends on how you combine them in your declarations:

dot notation vs ampersand

Basic Nesting with dot (“.”)

.parent {
    .child {
    }
}

This compiles to:

.parent .child {}

You can nest as deep as you’d like, but it’s a good practice to keep it only a level or two to prevent overly specific selectors (which are less useful and harder to override).

The & comes in handy when you’re nesting and you want to create a more specific selector, like an element that has both of two classes, like this:

.some-class.another-class { }

.some-class {
    &.another-class {
    }
}

This will compile to

.some-class.another-class

The & always refers to the parent selector when nesting. We can think of the & as a mechanism that allows us to place the parent selector wherever we need it in our child selector.

Using the & with pseudo classes

You can write pseudo classes on a class in a much less repetitive way with the &:

    .button {
  &:visited { }
  &:hover { }
  &:active { }
}

This compiles to:

.button:visited {
}
.button:hover {
}
.button:active {
}

The & in this case allows us to position .button directly next to pseudo classes without repetition in the authored code. If we left out the & from this example, basic nesting would put a space between them like this…

.button :hover

which isn’t the same.

And thats why at the root of the .scss file I can not have an ampersand &


&.sdk-ng-select .ng-dropdown-panel {
  @include sdk-ng-select();
}

It will give me following error

SassError: Base-level rules cannot contain the parent-selector-referencing character
.pagination {
  a {
    &:hover,
    &:focus {
      color: red;
    }
  }
}

// in this case, the & represents .pagination a, and will compile to:

.pagination a:hover, 
.pagination a:focus {
  color: red;
}

Another example

  .hoverable {
  color: #fff;
  &:hover {
    color: #ff0;
  }
}

The compiled CSS will be

  .hoverable {
  color: #fff;
}

// just replace the "&" with the parent selector (.hoverable)

.hoverable:hover {
  color: #ff0;
}

Nested ampersand – Very useful

The cool thing about ampersands is that they don’t only have to be at the beginning of a nested style definition.

Wherever you put an ampersand into your Sass selector definitions, it is interpreted to mean the parent scope of the current style being defined.

An application of the above is – sometimes you need to define a style that takes the context of the existing style, but only applies in a special case. For example, what if we need a different border treatment for our .hoverableelement when the parent class is .special

The SASS without a nested “&” would be below

.hoverable {
  color: #fff;
  &:hover {
    color: #ff0;
  }
}

.special .hoverable {
  border: 1px solid #f00;
}

Doing this required us to step out of our .hoverable selector and then re-define it inside a new selector. If there had been more levels of nesting, or more context that needed to be set, that could have been a fairly complex action.

But with the ampersand, Sass allows us to do the same thing without leaving the scope of the .hoverable selector:

.hoverable {
  color: #fff;
  &:hover {
    color: #ff0;
  }
  .special & {
    border: 1px solid #f00;
  }
}

Both of these Sass snippets will result in the following CSS:

.hoverable {
  color: #fff;
}

.hoverable:hover {
  color: #ff0;
}

.special .hoverable {
  border: 1px solid #f00;
}

Sass replaced the ampersand with the parent selector, defining a new selector inside of the .special selector. And note because here, there a single space before the “&” – so the generated css will also have a single space before the parent selector (i.e. before .hoverable )

Since & references the top-most selector, it can be extended with additional classes and/or an id like the pseudo class selectors. So let’s say there is a selector of .feature-class and we have an instance where it will be paired with .style-class, which changes the look of it. From within the .feature-class declaration block, we would have a child declaration that starts like this: &.style-class with its own declaration block.

Sass will replace “&” with .feature-class, which becomes feature-class.style-class in our generated CSS.

.feature-class {
        color: #0090B2;
        &:hover {
          color: #FF7A00;
        }
        &:active {
          color: #B25500;
        }
        &.style-class {
          color: #00CEFF;
          &:hover {
            color: #0090B2;
          }
          &:active {
            color: #FF7A00;
          }
        }
      }

Generated CSS

.feature-class {
      color: #0090B2;
    }
    .feature-class:hover {
      color: #FF7A00;
    }
    .feature-class:active {
      color: #B25500;
    }
    .feature-class.style-class {
      color: #00CEFF;
    }
    .feature-class.style-class:hover {
      color: #0090B2;
    }
    .feature-class.style-class:active {
      color: #FF7A00;
    }

css class definition with multiple identifiers in a single line – Understaning how it works

1> Chain Selectors –

https://stackoverflow.com/questions/13444647/css-class-definition-with-multiple-identifiers

.class1.class2 will match only the elements that have both of the classes defined.

.class1.class2 { background: red; }

<div class="class1 class2"></div>

.class1, .class2 (i.e. a comma and a space in between) will match the elements with .class1 or .class2

.class1, class2 { background: yellow; }

<div class="class1"></div>
<div class="class2"></div>

Chain selectors are not limited just to classes, you can do it for both classes and ids.

Classes

.classA.classB {
/*style here*/
}

Class & Id

.classA#idB {

/*style here*/
}

Id & Id

#idA#idB {
/*style here*/
}

2> Descendant Selector

.class1 .class2 will match only the elements with class2 within elements with class1.

.class1 .class2 { background: blue; }

<div class="class1">
    <div class="class2"></div>
</div>

3> Child Selector

The child selector selects all elements that are the children of a specified element.

The following example selects all

elements that are children of a

element:

div > p {
    background-color: yellow;
}

I was working ng-select Angular package, and for my case here, I am trying to target both the below 2 classes

class="ng-select ng-dropdown-panel"

// And also
class="ng-dropdown-panel sdk-ng-select"

Note when I use component (which is the popular angular package) in .html file all ng-select related classes will have the ultimate parent ‘ng-select’

Here’s my overall structur of the @mixin in .scss file

@mixin sdk-ng-select {
    ...many styles here
.ng-dropdown-panel,
  &.ng-dropdown-panel.sdk-ng-select {
    .ng-dropdown-footer {
      @extend .sdk-text-body-light-2;
      display: flex;
      align-items: center;
      justify-content: center;      
    }
...many styles here
}

.sdk-ng-select {
  @include sdk-ng-select();
}

Then in an .html file of Angular component was consuming the above style as below

<ng-select class=”sdk-ng-select”

The above will work, but its the wrong way to handle.

Problem with above

&.ng-dropdown-panel.sdk-ng-select should not be required.

I could simply do

.ng-dropdown-panel, &.ng-dropdown-panel

In the above, the first selector (.ng-dropdown-panel) matches “ng-dropdown-panel” inside the “ng-select”

The second selector (&.ng-dropdown-panel) matches

i.e. both the classes

.ng-dropdown-panel.sdk-ng-select

Recollect, the way ampersand work, that it will replace “&” with .parent-class, which becomes

.ng-dropdown-panel.sdk-ng-select in our generated CSS.

The downside to repeating the .sdk-ng-select selector inside the mixing (as I was doing in the top of this page) is that mixin is made in a way where it does not know about the class .sdk-ng-select, instead, it is used inside it, like below.

  .sdk-ng-select {
  @include sdk-ng-select();
}

And having the selector .sdk-ng-select inside the mixin breaks this structure.

So the correct version would be

  .ng-dropdown-panel,
  &.ng-dropdown-panel {
    .ng-dropdown-footer {
      @extend .sdk-text-body-light-2;
      display: flex;
      
    }

The meaning of a selector with more classes depends on how you combine them in your declarations:

Relevant issue in Saas github repo

“This error has existed since 3.0 which was released in May 2010.

It’s nonsensical to refer to a parent selector at the base-level of a stylesheet. Inferring that & should be the universal selector at the root level is not at all a safe assumption. Additionally, this is often indicative of a coding mistake. So we consider it an error.”

Further Reading

https://css-tricks.com/the-sass-ampersand/

Patient safety assistant

Check your symptom safely

Hi, I am RX Symptom Navigator. I can help you understand what to read next and what warning signs need care.
Warning: Do not use this in emergencies, pregnancy, severe illness, or as a substitute for a doctor. For children or teens, use with a parent/guardian and clinician.
A rural-friendly guide: warning signs, when to see a doctor, related articles, tests to discuss, and OTC safety education.
1 Symptom 2 Severity 3 Safe guidance
First safety question

Is there chest pain, breathing trouble, fainting, confusion, severe bleeding, stroke-like weakness, severe injury, or pregnancy danger sign?

Choose quickly

Browse by body area
Start here: Write or select a symptom. The guide will show warning signs, doctor guidance, diagnostic tests to discuss, OTC safety education, and related RX articles.

Important: This tool is educational only. It cannot diagnose, treat, or replace a doctor. OTC information is not a prescription. In an emergency, contact local emergency services or go to the nearest hospital.

Doctor visit helper

Prepare before seeing a doctor

A simple rural-patient checklist to help you explain symptoms clearly, ask better questions, and avoid unsafe self-treatment.

Safety note: This is not a prescription or diagnosis. For severe symptoms, pregnancy danger signs, children with serious illness, chest pain, breathing difficulty, stroke-like weakness, or major injury, seek urgent care.

Which doctor may help?

Start with a registered doctor or the nearest qualified health center.

What to tell the doctor

  • Write when the problem started and how it changed.
  • Bring old prescriptions, investigation reports, and current medicines.
  • Write allergies, pregnancy status, diabetes, kidney/liver disease, and major past illnesses.
  • Bring one family member if the patient is weak, elderly, confused, or a child.

Questions to ask

  • What is the most likely cause of my symptoms?
  • Which danger signs mean I should go to hospital quickly?
  • Which tests are necessary now, and which can wait?
  • How should I take medicines safely and what side effects should I watch for?
  • When should I come for follow-up?

Tests to discuss

  • Vital signs: temperature, pulse, blood pressure, oxygen saturation
  • Basic physical examination by a clinician
  • CBC, urine test, blood sugar, or imaging only when clinically needed

Avoid these mistakes

  • Do not use antibiotics, steroid tablets/injections, or strong painkillers without proper medical advice.
  • Do not hide pregnancy, kidney disease, ulcer, allergy, or blood thinner use.
  • Do not delay emergency care when danger signs are present.

Medicine safety and first-aid guide

This section is for patient education only. It does not replace a doctor, pharmacist, or emergency care.

Safe first steps

  • Rest, drink safe water, and observe symptoms carefully.
  • Keep a written note of symptoms, duration, temperature, medicines already taken, and allergy history.
  • Seek medical care quickly if symptoms are severe, worsening, or unusual for the patient.

OTC medicine safety

  • For mild pain or fever, ask a registered pharmacist or doctor before using common over-the-counter pain/fever medicines.
  • Do not combine multiple pain medicines without advice, especially if you have kidney disease, liver disease, stomach ulcer, asthma, pregnancy, or take blood thinners.
  • Do not give adult medicines to children unless a qualified clinician advises it.

Avoid these mistakes

  • Do not start antibiotics without a proper medical decision.
  • Do not use steroid tablets or injections casually for quick relief.
  • Do not delay emergency care because of home remedies.

Get urgent help if

  • Severe symptoms, confusion, fainting, breathing difficulty, chest pain, severe dehydration, or sudden weakness need urgent medical care.
Medicine names, dose, and timing must be decided by a qualified clinician or pharmacist after checking age, pregnancy, allergy, other diseases, and current medicines.

For rural patients and family caregivers

Patient health record and symptom diary

Write your symptoms, medicines already taken, test results, and questions before visiting a doctor. This note stays on your device unless you print or copy it.

Doctor to discuss: Doctor / qualified healthcare provider
Tests to discuss with doctor
  • Basic vital signs: temperature, pulse, blood pressure, oxygen level if needed
  • Relevant blood, urine, imaging, or specialist tests only after clinical assessment
Questions to ask
  • What is the most likely cause of my symptoms?
  • Which warning signs mean I should go to emergency care?
  • Which tests are really needed now?
  • Which medicines are safe for my age, pregnancy status, allergy, kidney/liver/stomach condition, and current medicines?

Emergency warning signs such as chest pain, severe breathing difficulty, sudden weakness, confusion, severe dehydration, major injury, or loss of bladder/bowel control need urgent medical care. Do not wait for online information.

Safe pathway to proper treatment

Patient care roadmap

Use this simple roadmap to understand the next safe steps. It is educational and does not replace examination by a doctor.

Go to emergency care if you notice:
  • Severe or rapidly worsening symptoms
  • Breathing difficulty, chest pain, fainting, confusion, severe weakness, major injury, or severe dehydration
Doctor / service to discuss: Qualified healthcare provider; specialist depends on symptoms and examination.
  1. Step 1

    Check danger signs first

    If danger signs are present, seek emergency care and do not wait for online information.

  2. Step 2

    Record the symptom story

    Write when symptoms started, severity, medicines already taken, allergies, pregnancy status, and test results.

  3. Step 3

    Visit a qualified clinician

    A doctor, nurse, or qualified healthcare provider can examine you and decide which tests or treatment are needed.

  4. Step 4

    Do only useful tests

    Do tests after clinical assessment. Avoid unnecessary tests, random antibiotics, or repeated medicines without diagnosis.

  5. Step 5

    Follow up and return early if worse

    If symptoms worsen, new warning signs appear, or treatment is not helping, return for review quickly.

Rural patient practical tips
  • Take a written symptom diary and all previous prescriptions/test reports.
  • Do not hide medicines already taken, even herbal or over-the-counter medicines.
  • Ask which warning signs mean urgent referral to hospital.

This roadmap is for education. A real diagnosis and treatment plan requires history, examination, and clinical judgment.

Frequently Asked Questions

Is this article a replacement for a doctor?

No. It is educational content only. Patients should consult a qualified clinician for diagnosis and treatment.

When should I seek urgent care?

Seek urgent care for severe symptoms, rapidly worsening condition, breathing difficulty, severe pain, neurological changes, or any emergency warning sign.

References

Add references, clinical guidelines, textbooks, journal articles, or trusted medical sources here. You can edit this area from the RX Article Professional Blocks panel.