In
Sass, the ampersand
& is a special character that is used to reference the parent selector in a nested context. It is often used to concatenate or combine selectors.
The
& is a powerful feature in
Sass, allowing you to generate more concise and maintainable
css by referencing and combining selectors in a nested structure.
In the
li block, the
& is a reference to the
.navigation li selector. So,
&:first-child is equivalent to
.navigation li:first-child. It targets the first
li element inside the
.navigation element and removes its left margin.
Sass:
$color-text-dark: black;
.navigation {
list-style: none;
float: left;
li {
display: inline-block;
margin-left: 30px;
&:first-child {
margin: 0;
}
a:link {
text-decoration: none;
text-transform: uppercase;
color: $color-text-dark;
}
}
}
|
CSS:
.navigation {
list-style: none;
float: left;
}
.navigation li {
display: inline-block;
margin-left: 30px;
}
.navigation li:first-child {
margin: 0;
}
.navigation li a:link {
text-decoration: none;
text-transform: uppercase;
color: black;
}
|
Sass:
$color-text-dark: black;
.navigation {
list-style: none;
float: left;
li {
display: inline-block;
margin-left: 30px;
&:first-child {
margin: 0;
}
a:link {
text-decoration: none;
text-transform: uppercase;
color: $color-text-dark;
}
}
}
|
Sass:
$color-text-dark: black;
.navigation {
list-style: none;
float: left;
li {
display: inline-block;
margin-left: 30px;
&:first-child {
margin: 0;
}
& a:link {
text-decoration: none;
text-transform: uppercase;
color: $color-text-dark;
}
}
}
|
CSS:
.navigation {
list-style: none;
float: left;
}
.navigation li {
display: inline-block;
margin-left: 30px;
}
.navigation li:first-child {
margin: 0;
}
.navigation li a:link {
text-decoration: none;
text-transform: uppercase;
color: black;
}
|