Reputation: 2282
The first one:
.social {
margin: 0;
padding: 0;
list-style: none;
display: flex;
> li > a {
position: relative;
display: block;
width: 26px;
height: 26px;
background: #fff;
border-radius: .1875em;
}
> li + li {
margin-left: .8em;
}
}
The second one:
.social {
margin: 0;
padding: 0;
list-style: none;
display: flex;
& > li > a {
position: relative;
display: block;
width: 26px;
height: 26px;
background: #fff;
border-radius: .1875em;
}
& > li + li {
margin-left: .8em;
}
}
The only difference between the two is that the second one uses the ampersand &
.
The &
gets the parent name, however even if I use > li > a
as seen in the first code snippet the output will include the parent name .social>li>a
as well.
Is the first one okay? Just to use it without the ampersand?
Upvotes: 0
Views: 470
Reputation: 3084
Exact. In your example both results will be the same. Both examples generates a class construct for child classe which are written with a space between.
The ampersand &
is needed to write css for i.e. pseudo classes, when there is no space between:
// sass
.class {
color: green;
&:hover {
color: red;
}
}
// result will be without space....
.class {
color: green;
}
.class:hover {
color: red;
}
Upvotes: 1