Different color classes that control the same stuff
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
2
down vote
favorite
I have this code...
& .light-green
background: linear-gradient(135deg, #128465 0%, #99ca3c 100%);
height: 100%;
& .card__header
background: #128465;
&::before
content: "";
display: inline-block;
width: 0;
position: absolute;
height: 0;
left: 0;
margin: 0 auto;
right: 0;
top: 100%;
border-style: solid;
border-width: 10px 10px 0 10px;
border-color: #128465 transparent transparent transparent;
& .icon-icon-resolved,
& .icon-icon-file
color: #128465;
& .card__actions
background: linear-gradient(-45deg, #128465 0%, #99ca3c 100%);
& .dark-green
background: linear-gradient(135deg, #336666 0%, #33bc69 100%);
height: 100%;
& .card__header
background: #336666;
&::before
content: "";
display: inline-block;
width: 0;
position: absolute;
height: 0;
left: 0;
margin: 0 auto;
right: 0;
top: 100%;
border-style: solid;
border-width: 10px 10px 0 10px;
border-color: #336666 transparent transparent transparent;
& .icon-icon-resolved,
& .icon-icon-file
color: #336666;
& .card__actions
background: linear-gradient(135deg, #336666 0%, #33bc69 100%);
& .aqua
background: linear-gradient(135deg, #006699 0%, #33bc99 100%);
height: 100%;
& .card__header
background: #006699;
&::before
content: "";
display: inline-block;
width: 0;
position: absolute;
height: 0;
left: 0;
margin: 0 auto;
right: 0;
top: 100%;
border-style: solid;
border-width: 10px 10px 0 10px;
border-color: #006699 transparent transparent transparent;
& .icon-icon-resolved,
& .icon-icon-file
color: #006699;
& .card__actions
background: linear-gradient(135deg, #006699 0%, #33bc99 100%);
& .blue
background: linear-gradient(135deg, #294c95 0%, #4abed8 100%);
height: 100%;
& .card__header
background: #294c95;
&::before
content: "";
display: inline-block;
width: 0;
position: absolute;
height: 0;
left: 0;
margin: 0 auto;
right: 0;
top: 100%;
border-style: solid;
border-width: 10px 10px 0 10px;
border-color: #294c95 transparent transparent transparent;
& .icon-icon-resolved,
& .icon-icon-file
color: #294c95;
& .card__actions
background: linear-gradient(135deg, #294c95 0%, #4abed8 100%);
.blue-purple
background: linear-gradient(135deg, #50278f 0%, #4a8cd8 100%);
height: 100%;
& .card__header
background: #50278f;
&::before
content: "";
display: inline-block;
width: 0;
position: absolute;
height: 0;
left: 0;
margin: 0 auto;
right: 0;
top: 100%;
border-style: solid;
border-width: 10px 10px 0 10px;
border-color: #50278f transparent transparent transparent;
& .icon-icon-resolved,
& .icon-icon-file
color: #50278f;
& .card__actions
background: linear-gradient(135deg, #50278f 0%, #4a8cd8 100%);
.purple
background: linear-gradient(135deg, #424c9f 0%, #c16cf9 100%);
height: 100%;
& .card__header
background: #424c9f;
&::before
content: "";
display: inline-block;
width: 0;
position: absolute;
height: 0;
left: 0;
margin: 0 auto;
right: 0;
top: 100%;
border-style: solid;
border-width: 10px 10px 0 10px;
border-color: #424c9f transparent transparent transparent;
& .icon-icon-resolved,
& .icon-icon-file
color: #424c9f;
& .card__actions
background: linear-gradient(135deg, #424c9f 0%, #c16cf9 100%);
.purple-pink
background: linear-gradient(135deg, #522cae 0%, #be4f7e 100%);
height: 100%;
& .card__header
background: #522cae;
&::before
content: "";
display: inline-block;
width: 0;
position: absolute;
height: 0;
left: 0;
margin: 0 auto;
right: 0;
top: 100%;
border-style: solid;
border-width: 10px 10px 0 10px;
border-color: #522cae transparent transparent transparent;
& .icon-icon-resolved,
& .icon-icon-file
color: #522cae;
& .card__actions
background: linear-gradient(135deg, #522cae 0%, #be4f7e 100%);
.purple-orange
background: linear-gradient(135deg, #ce00aa 0%, #ffa600 100%);
height: 100%;
& .card__header
background: #ce00aa;
&::before
content: "";
display: inline-block;
width: 0;
position: absolute;
height: 0;
left: 0;
margin: 0 auto;
right: 0;
top: 100%;
border-style: solid;
border-width: 10px 10px 0 10px;
border-color: #ce00aa transparent transparent transparent;
& .icon-icon-resolved,
& .icon-icon-file
color: #ce00aa;
& .card__actions
background: linear-gradient(135deg, #ce00aa 0%, #ffa600 100%);
now as you can see its basically the same code the only thing that changes are the gradients and the colours.. but Im not entirely sure how I can dry this up??
any help would be appreciated!
css sass
add a comment |Â
up vote
2
down vote
favorite
I have this code...
& .light-green
background: linear-gradient(135deg, #128465 0%, #99ca3c 100%);
height: 100%;
& .card__header
background: #128465;
&::before
content: "";
display: inline-block;
width: 0;
position: absolute;
height: 0;
left: 0;
margin: 0 auto;
right: 0;
top: 100%;
border-style: solid;
border-width: 10px 10px 0 10px;
border-color: #128465 transparent transparent transparent;
& .icon-icon-resolved,
& .icon-icon-file
color: #128465;
& .card__actions
background: linear-gradient(-45deg, #128465 0%, #99ca3c 100%);
& .dark-green
background: linear-gradient(135deg, #336666 0%, #33bc69 100%);
height: 100%;
& .card__header
background: #336666;
&::before
content: "";
display: inline-block;
width: 0;
position: absolute;
height: 0;
left: 0;
margin: 0 auto;
right: 0;
top: 100%;
border-style: solid;
border-width: 10px 10px 0 10px;
border-color: #336666 transparent transparent transparent;
& .icon-icon-resolved,
& .icon-icon-file
color: #336666;
& .card__actions
background: linear-gradient(135deg, #336666 0%, #33bc69 100%);
& .aqua
background: linear-gradient(135deg, #006699 0%, #33bc99 100%);
height: 100%;
& .card__header
background: #006699;
&::before
content: "";
display: inline-block;
width: 0;
position: absolute;
height: 0;
left: 0;
margin: 0 auto;
right: 0;
top: 100%;
border-style: solid;
border-width: 10px 10px 0 10px;
border-color: #006699 transparent transparent transparent;
& .icon-icon-resolved,
& .icon-icon-file
color: #006699;
& .card__actions
background: linear-gradient(135deg, #006699 0%, #33bc99 100%);
& .blue
background: linear-gradient(135deg, #294c95 0%, #4abed8 100%);
height: 100%;
& .card__header
background: #294c95;
&::before
content: "";
display: inline-block;
width: 0;
position: absolute;
height: 0;
left: 0;
margin: 0 auto;
right: 0;
top: 100%;
border-style: solid;
border-width: 10px 10px 0 10px;
border-color: #294c95 transparent transparent transparent;
& .icon-icon-resolved,
& .icon-icon-file
color: #294c95;
& .card__actions
background: linear-gradient(135deg, #294c95 0%, #4abed8 100%);
.blue-purple
background: linear-gradient(135deg, #50278f 0%, #4a8cd8 100%);
height: 100%;
& .card__header
background: #50278f;
&::before
content: "";
display: inline-block;
width: 0;
position: absolute;
height: 0;
left: 0;
margin: 0 auto;
right: 0;
top: 100%;
border-style: solid;
border-width: 10px 10px 0 10px;
border-color: #50278f transparent transparent transparent;
& .icon-icon-resolved,
& .icon-icon-file
color: #50278f;
& .card__actions
background: linear-gradient(135deg, #50278f 0%, #4a8cd8 100%);
.purple
background: linear-gradient(135deg, #424c9f 0%, #c16cf9 100%);
height: 100%;
& .card__header
background: #424c9f;
&::before
content: "";
display: inline-block;
width: 0;
position: absolute;
height: 0;
left: 0;
margin: 0 auto;
right: 0;
top: 100%;
border-style: solid;
border-width: 10px 10px 0 10px;
border-color: #424c9f transparent transparent transparent;
& .icon-icon-resolved,
& .icon-icon-file
color: #424c9f;
& .card__actions
background: linear-gradient(135deg, #424c9f 0%, #c16cf9 100%);
.purple-pink
background: linear-gradient(135deg, #522cae 0%, #be4f7e 100%);
height: 100%;
& .card__header
background: #522cae;
&::before
content: "";
display: inline-block;
width: 0;
position: absolute;
height: 0;
left: 0;
margin: 0 auto;
right: 0;
top: 100%;
border-style: solid;
border-width: 10px 10px 0 10px;
border-color: #522cae transparent transparent transparent;
& .icon-icon-resolved,
& .icon-icon-file
color: #522cae;
& .card__actions
background: linear-gradient(135deg, #522cae 0%, #be4f7e 100%);
.purple-orange
background: linear-gradient(135deg, #ce00aa 0%, #ffa600 100%);
height: 100%;
& .card__header
background: #ce00aa;
&::before
content: "";
display: inline-block;
width: 0;
position: absolute;
height: 0;
left: 0;
margin: 0 auto;
right: 0;
top: 100%;
border-style: solid;
border-width: 10px 10px 0 10px;
border-color: #ce00aa transparent transparent transparent;
& .icon-icon-resolved,
& .icon-icon-file
color: #ce00aa;
& .card__actions
background: linear-gradient(135deg, #ce00aa 0%, #ffa600 100%);
now as you can see its basically the same code the only thing that changes are the gradients and the colours.. but Im not entirely sure how I can dry this up??
any help would be appreciated!
css sass
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I have this code...
& .light-green
background: linear-gradient(135deg, #128465 0%, #99ca3c 100%);
height: 100%;
& .card__header
background: #128465;
&::before
content: "";
display: inline-block;
width: 0;
position: absolute;
height: 0;
left: 0;
margin: 0 auto;
right: 0;
top: 100%;
border-style: solid;
border-width: 10px 10px 0 10px;
border-color: #128465 transparent transparent transparent;
& .icon-icon-resolved,
& .icon-icon-file
color: #128465;
& .card__actions
background: linear-gradient(-45deg, #128465 0%, #99ca3c 100%);
& .dark-green
background: linear-gradient(135deg, #336666 0%, #33bc69 100%);
height: 100%;
& .card__header
background: #336666;
&::before
content: "";
display: inline-block;
width: 0;
position: absolute;
height: 0;
left: 0;
margin: 0 auto;
right: 0;
top: 100%;
border-style: solid;
border-width: 10px 10px 0 10px;
border-color: #336666 transparent transparent transparent;
& .icon-icon-resolved,
& .icon-icon-file
color: #336666;
& .card__actions
background: linear-gradient(135deg, #336666 0%, #33bc69 100%);
& .aqua
background: linear-gradient(135deg, #006699 0%, #33bc99 100%);
height: 100%;
& .card__header
background: #006699;
&::before
content: "";
display: inline-block;
width: 0;
position: absolute;
height: 0;
left: 0;
margin: 0 auto;
right: 0;
top: 100%;
border-style: solid;
border-width: 10px 10px 0 10px;
border-color: #006699 transparent transparent transparent;
& .icon-icon-resolved,
& .icon-icon-file
color: #006699;
& .card__actions
background: linear-gradient(135deg, #006699 0%, #33bc99 100%);
& .blue
background: linear-gradient(135deg, #294c95 0%, #4abed8 100%);
height: 100%;
& .card__header
background: #294c95;
&::before
content: "";
display: inline-block;
width: 0;
position: absolute;
height: 0;
left: 0;
margin: 0 auto;
right: 0;
top: 100%;
border-style: solid;
border-width: 10px 10px 0 10px;
border-color: #294c95 transparent transparent transparent;
& .icon-icon-resolved,
& .icon-icon-file
color: #294c95;
& .card__actions
background: linear-gradient(135deg, #294c95 0%, #4abed8 100%);
.blue-purple
background: linear-gradient(135deg, #50278f 0%, #4a8cd8 100%);
height: 100%;
& .card__header
background: #50278f;
&::before
content: "";
display: inline-block;
width: 0;
position: absolute;
height: 0;
left: 0;
margin: 0 auto;
right: 0;
top: 100%;
border-style: solid;
border-width: 10px 10px 0 10px;
border-color: #50278f transparent transparent transparent;
& .icon-icon-resolved,
& .icon-icon-file
color: #50278f;
& .card__actions
background: linear-gradient(135deg, #50278f 0%, #4a8cd8 100%);
.purple
background: linear-gradient(135deg, #424c9f 0%, #c16cf9 100%);
height: 100%;
& .card__header
background: #424c9f;
&::before
content: "";
display: inline-block;
width: 0;
position: absolute;
height: 0;
left: 0;
margin: 0 auto;
right: 0;
top: 100%;
border-style: solid;
border-width: 10px 10px 0 10px;
border-color: #424c9f transparent transparent transparent;
& .icon-icon-resolved,
& .icon-icon-file
color: #424c9f;
& .card__actions
background: linear-gradient(135deg, #424c9f 0%, #c16cf9 100%);
.purple-pink
background: linear-gradient(135deg, #522cae 0%, #be4f7e 100%);
height: 100%;
& .card__header
background: #522cae;
&::before
content: "";
display: inline-block;
width: 0;
position: absolute;
height: 0;
left: 0;
margin: 0 auto;
right: 0;
top: 100%;
border-style: solid;
border-width: 10px 10px 0 10px;
border-color: #522cae transparent transparent transparent;
& .icon-icon-resolved,
& .icon-icon-file
color: #522cae;
& .card__actions
background: linear-gradient(135deg, #522cae 0%, #be4f7e 100%);
.purple-orange
background: linear-gradient(135deg, #ce00aa 0%, #ffa600 100%);
height: 100%;
& .card__header
background: #ce00aa;
&::before
content: "";
display: inline-block;
width: 0;
position: absolute;
height: 0;
left: 0;
margin: 0 auto;
right: 0;
top: 100%;
border-style: solid;
border-width: 10px 10px 0 10px;
border-color: #ce00aa transparent transparent transparent;
& .icon-icon-resolved,
& .icon-icon-file
color: #ce00aa;
& .card__actions
background: linear-gradient(135deg, #ce00aa 0%, #ffa600 100%);
now as you can see its basically the same code the only thing that changes are the gradients and the colours.. but Im not entirely sure how I can dry this up??
any help would be appreciated!
css sass
I have this code...
& .light-green
background: linear-gradient(135deg, #128465 0%, #99ca3c 100%);
height: 100%;
& .card__header
background: #128465;
&::before
content: "";
display: inline-block;
width: 0;
position: absolute;
height: 0;
left: 0;
margin: 0 auto;
right: 0;
top: 100%;
border-style: solid;
border-width: 10px 10px 0 10px;
border-color: #128465 transparent transparent transparent;
& .icon-icon-resolved,
& .icon-icon-file
color: #128465;
& .card__actions
background: linear-gradient(-45deg, #128465 0%, #99ca3c 100%);
& .dark-green
background: linear-gradient(135deg, #336666 0%, #33bc69 100%);
height: 100%;
& .card__header
background: #336666;
&::before
content: "";
display: inline-block;
width: 0;
position: absolute;
height: 0;
left: 0;
margin: 0 auto;
right: 0;
top: 100%;
border-style: solid;
border-width: 10px 10px 0 10px;
border-color: #336666 transparent transparent transparent;
& .icon-icon-resolved,
& .icon-icon-file
color: #336666;
& .card__actions
background: linear-gradient(135deg, #336666 0%, #33bc69 100%);
& .aqua
background: linear-gradient(135deg, #006699 0%, #33bc99 100%);
height: 100%;
& .card__header
background: #006699;
&::before
content: "";
display: inline-block;
width: 0;
position: absolute;
height: 0;
left: 0;
margin: 0 auto;
right: 0;
top: 100%;
border-style: solid;
border-width: 10px 10px 0 10px;
border-color: #006699 transparent transparent transparent;
& .icon-icon-resolved,
& .icon-icon-file
color: #006699;
& .card__actions
background: linear-gradient(135deg, #006699 0%, #33bc99 100%);
& .blue
background: linear-gradient(135deg, #294c95 0%, #4abed8 100%);
height: 100%;
& .card__header
background: #294c95;
&::before
content: "";
display: inline-block;
width: 0;
position: absolute;
height: 0;
left: 0;
margin: 0 auto;
right: 0;
top: 100%;
border-style: solid;
border-width: 10px 10px 0 10px;
border-color: #294c95 transparent transparent transparent;
& .icon-icon-resolved,
& .icon-icon-file
color: #294c95;
& .card__actions
background: linear-gradient(135deg, #294c95 0%, #4abed8 100%);
.blue-purple
background: linear-gradient(135deg, #50278f 0%, #4a8cd8 100%);
height: 100%;
& .card__header
background: #50278f;
&::before
content: "";
display: inline-block;
width: 0;
position: absolute;
height: 0;
left: 0;
margin: 0 auto;
right: 0;
top: 100%;
border-style: solid;
border-width: 10px 10px 0 10px;
border-color: #50278f transparent transparent transparent;
& .icon-icon-resolved,
& .icon-icon-file
color: #50278f;
& .card__actions
background: linear-gradient(135deg, #50278f 0%, #4a8cd8 100%);
.purple
background: linear-gradient(135deg, #424c9f 0%, #c16cf9 100%);
height: 100%;
& .card__header
background: #424c9f;
&::before
content: "";
display: inline-block;
width: 0;
position: absolute;
height: 0;
left: 0;
margin: 0 auto;
right: 0;
top: 100%;
border-style: solid;
border-width: 10px 10px 0 10px;
border-color: #424c9f transparent transparent transparent;
& .icon-icon-resolved,
& .icon-icon-file
color: #424c9f;
& .card__actions
background: linear-gradient(135deg, #424c9f 0%, #c16cf9 100%);
.purple-pink
background: linear-gradient(135deg, #522cae 0%, #be4f7e 100%);
height: 100%;
& .card__header
background: #522cae;
&::before
content: "";
display: inline-block;
width: 0;
position: absolute;
height: 0;
left: 0;
margin: 0 auto;
right: 0;
top: 100%;
border-style: solid;
border-width: 10px 10px 0 10px;
border-color: #522cae transparent transparent transparent;
& .icon-icon-resolved,
& .icon-icon-file
color: #522cae;
& .card__actions
background: linear-gradient(135deg, #522cae 0%, #be4f7e 100%);
.purple-orange
background: linear-gradient(135deg, #ce00aa 0%, #ffa600 100%);
height: 100%;
& .card__header
background: #ce00aa;
&::before
content: "";
display: inline-block;
width: 0;
position: absolute;
height: 0;
left: 0;
margin: 0 auto;
right: 0;
top: 100%;
border-style: solid;
border-width: 10px 10px 0 10px;
border-color: #ce00aa transparent transparent transparent;
& .icon-icon-resolved,
& .icon-icon-file
color: #ce00aa;
& .card__actions
background: linear-gradient(135deg, #ce00aa 0%, #ffa600 100%);
now as you can see its basically the same code the only thing that changes are the gradients and the colours.. but Im not entirely sure how I can dry this up??
any help would be appreciated!
css sass
asked May 10 at 6:06
Smokey Dawson
1134
1134
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
3
down vote
accepted
- Move all your duplicate code into a class, say
gradient
. Pick better names. A class name like
light-green
can mean anything, can be put on anything and really is not that great.I like Microsoft's (Fabric UI) method to fix this. You define your base class, say
gradient
, and then add your customizations via a subclass, saygradient--light-green
. The double hyphen helps a lot when you come across these in the wild.I don't know SASS but given my knowledge of CSS, you should be able to make a new class with all the colours removed from your class. This will be your base class. Take:
& .gradient
height: 100%;
& .card__header
&::before
content: "";
display: inline-block;
width: 0;
position: absolute;
height: 0;
left: 0;
margin: 0 auto;
right: 0;
top: 100%;
border-style: solid;
border-width: 10px 10px 0 10px;
You then just need to remove this from your other classes. Leaving something like:
& .gradient--light-green
background: linear-gradient(135deg, #128465 0%, #99ca3c 100%);
& .card__header
background: #128465;
&::before
border-color: $color1 transparent transparent transparent;
& .icon-icon-resolved,
& .icon-icon-file
color: #128465;
& .card__actions
background: linear-gradient(-45deg, #128465 0%, #99ca3c 100%);
Notice that all of these are the same. (Except
light-green
, which has a gradient with-45deg
, where all others have135deg
)Learn how to use a mixin, and make something like: (IDK if it works)
@mixin gradient-colors($color1, $color2)
background: linear-gradient(135deg, $color1 0%, $color2 100%);
& .card__header
background: $color1;
&::before
border-color: $color1 transparent transparent transparent;
& .icon-icon-resolved,
& .icon-icon-file
color: $color1;
& .card__actions
background: linear-gradient(135deg, $color1 0%, $color2 100%);
& .gradient--light-green
@include gradient-colors(#128465, #99ca3c);
And so now you're left with:
& .gradient
height: 100%;
& .card__header
&::before
content: "";
display: inline-block;
width: 0;
position: absolute;
height: 0;
left: 0;
margin: 0 auto;
right: 0;
top: 100%;
border-style: solid;
border-width: 10px 10px 0 10px;
@mixin gradient-colors($color1, $color2)
background: linear-gradient(135deg, $color1 0%, $color2 100%);
& .card__header
background: $color1;
&::before
border-color: $color1 transparent transparent transparent;
& .icon-icon-resolved,
& .icon-icon-file
color: $color1;
& .card__actions
background: linear-gradient(135deg, $color1 0%, $color2 100%);
& .gradient--light-green
@include gradient-colors(#128465, #99ca3c);
& .gradient--dark-green
@include gradient-colors(#336666, #33bc69);
& .gradient--aqua
@include gradient-colors(#006699, #33bc99);
& .gradient--blue
@include gradient-colors(#294c95, #4abed8);
& .gradient--blue-purple
@include gradient-colors(#50278f, #4a8cd8);
& .gradient--purple
@include gradient-colors(#424c9f, #c16cf9);
& .gradient--purple-pink
@include gradient-colors(#522cae, #be4f7e);
& .gradient--purple-orange
@include gradient-colors(#ce00aa, #ffa600);
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
- Move all your duplicate code into a class, say
gradient
. Pick better names. A class name like
light-green
can mean anything, can be put on anything and really is not that great.I like Microsoft's (Fabric UI) method to fix this. You define your base class, say
gradient
, and then add your customizations via a subclass, saygradient--light-green
. The double hyphen helps a lot when you come across these in the wild.I don't know SASS but given my knowledge of CSS, you should be able to make a new class with all the colours removed from your class. This will be your base class. Take:
& .gradient
height: 100%;
& .card__header
&::before
content: "";
display: inline-block;
width: 0;
position: absolute;
height: 0;
left: 0;
margin: 0 auto;
right: 0;
top: 100%;
border-style: solid;
border-width: 10px 10px 0 10px;
You then just need to remove this from your other classes. Leaving something like:
& .gradient--light-green
background: linear-gradient(135deg, #128465 0%, #99ca3c 100%);
& .card__header
background: #128465;
&::before
border-color: $color1 transparent transparent transparent;
& .icon-icon-resolved,
& .icon-icon-file
color: #128465;
& .card__actions
background: linear-gradient(-45deg, #128465 0%, #99ca3c 100%);
Notice that all of these are the same. (Except
light-green
, which has a gradient with-45deg
, where all others have135deg
)Learn how to use a mixin, and make something like: (IDK if it works)
@mixin gradient-colors($color1, $color2)
background: linear-gradient(135deg, $color1 0%, $color2 100%);
& .card__header
background: $color1;
&::before
border-color: $color1 transparent transparent transparent;
& .icon-icon-resolved,
& .icon-icon-file
color: $color1;
& .card__actions
background: linear-gradient(135deg, $color1 0%, $color2 100%);
& .gradient--light-green
@include gradient-colors(#128465, #99ca3c);
And so now you're left with:
& .gradient
height: 100%;
& .card__header
&::before
content: "";
display: inline-block;
width: 0;
position: absolute;
height: 0;
left: 0;
margin: 0 auto;
right: 0;
top: 100%;
border-style: solid;
border-width: 10px 10px 0 10px;
@mixin gradient-colors($color1, $color2)
background: linear-gradient(135deg, $color1 0%, $color2 100%);
& .card__header
background: $color1;
&::before
border-color: $color1 transparent transparent transparent;
& .icon-icon-resolved,
& .icon-icon-file
color: $color1;
& .card__actions
background: linear-gradient(135deg, $color1 0%, $color2 100%);
& .gradient--light-green
@include gradient-colors(#128465, #99ca3c);
& .gradient--dark-green
@include gradient-colors(#336666, #33bc69);
& .gradient--aqua
@include gradient-colors(#006699, #33bc99);
& .gradient--blue
@include gradient-colors(#294c95, #4abed8);
& .gradient--blue-purple
@include gradient-colors(#50278f, #4a8cd8);
& .gradient--purple
@include gradient-colors(#424c9f, #c16cf9);
& .gradient--purple-pink
@include gradient-colors(#522cae, #be4f7e);
& .gradient--purple-orange
@include gradient-colors(#ce00aa, #ffa600);
add a comment |Â
up vote
3
down vote
accepted
- Move all your duplicate code into a class, say
gradient
. Pick better names. A class name like
light-green
can mean anything, can be put on anything and really is not that great.I like Microsoft's (Fabric UI) method to fix this. You define your base class, say
gradient
, and then add your customizations via a subclass, saygradient--light-green
. The double hyphen helps a lot when you come across these in the wild.I don't know SASS but given my knowledge of CSS, you should be able to make a new class with all the colours removed from your class. This will be your base class. Take:
& .gradient
height: 100%;
& .card__header
&::before
content: "";
display: inline-block;
width: 0;
position: absolute;
height: 0;
left: 0;
margin: 0 auto;
right: 0;
top: 100%;
border-style: solid;
border-width: 10px 10px 0 10px;
You then just need to remove this from your other classes. Leaving something like:
& .gradient--light-green
background: linear-gradient(135deg, #128465 0%, #99ca3c 100%);
& .card__header
background: #128465;
&::before
border-color: $color1 transparent transparent transparent;
& .icon-icon-resolved,
& .icon-icon-file
color: #128465;
& .card__actions
background: linear-gradient(-45deg, #128465 0%, #99ca3c 100%);
Notice that all of these are the same. (Except
light-green
, which has a gradient with-45deg
, where all others have135deg
)Learn how to use a mixin, and make something like: (IDK if it works)
@mixin gradient-colors($color1, $color2)
background: linear-gradient(135deg, $color1 0%, $color2 100%);
& .card__header
background: $color1;
&::before
border-color: $color1 transparent transparent transparent;
& .icon-icon-resolved,
& .icon-icon-file
color: $color1;
& .card__actions
background: linear-gradient(135deg, $color1 0%, $color2 100%);
& .gradient--light-green
@include gradient-colors(#128465, #99ca3c);
And so now you're left with:
& .gradient
height: 100%;
& .card__header
&::before
content: "";
display: inline-block;
width: 0;
position: absolute;
height: 0;
left: 0;
margin: 0 auto;
right: 0;
top: 100%;
border-style: solid;
border-width: 10px 10px 0 10px;
@mixin gradient-colors($color1, $color2)
background: linear-gradient(135deg, $color1 0%, $color2 100%);
& .card__header
background: $color1;
&::before
border-color: $color1 transparent transparent transparent;
& .icon-icon-resolved,
& .icon-icon-file
color: $color1;
& .card__actions
background: linear-gradient(135deg, $color1 0%, $color2 100%);
& .gradient--light-green
@include gradient-colors(#128465, #99ca3c);
& .gradient--dark-green
@include gradient-colors(#336666, #33bc69);
& .gradient--aqua
@include gradient-colors(#006699, #33bc99);
& .gradient--blue
@include gradient-colors(#294c95, #4abed8);
& .gradient--blue-purple
@include gradient-colors(#50278f, #4a8cd8);
& .gradient--purple
@include gradient-colors(#424c9f, #c16cf9);
& .gradient--purple-pink
@include gradient-colors(#522cae, #be4f7e);
& .gradient--purple-orange
@include gradient-colors(#ce00aa, #ffa600);
add a comment |Â
up vote
3
down vote
accepted
up vote
3
down vote
accepted
- Move all your duplicate code into a class, say
gradient
. Pick better names. A class name like
light-green
can mean anything, can be put on anything and really is not that great.I like Microsoft's (Fabric UI) method to fix this. You define your base class, say
gradient
, and then add your customizations via a subclass, saygradient--light-green
. The double hyphen helps a lot when you come across these in the wild.I don't know SASS but given my knowledge of CSS, you should be able to make a new class with all the colours removed from your class. This will be your base class. Take:
& .gradient
height: 100%;
& .card__header
&::before
content: "";
display: inline-block;
width: 0;
position: absolute;
height: 0;
left: 0;
margin: 0 auto;
right: 0;
top: 100%;
border-style: solid;
border-width: 10px 10px 0 10px;
You then just need to remove this from your other classes. Leaving something like:
& .gradient--light-green
background: linear-gradient(135deg, #128465 0%, #99ca3c 100%);
& .card__header
background: #128465;
&::before
border-color: $color1 transparent transparent transparent;
& .icon-icon-resolved,
& .icon-icon-file
color: #128465;
& .card__actions
background: linear-gradient(-45deg, #128465 0%, #99ca3c 100%);
Notice that all of these are the same. (Except
light-green
, which has a gradient with-45deg
, where all others have135deg
)Learn how to use a mixin, and make something like: (IDK if it works)
@mixin gradient-colors($color1, $color2)
background: linear-gradient(135deg, $color1 0%, $color2 100%);
& .card__header
background: $color1;
&::before
border-color: $color1 transparent transparent transparent;
& .icon-icon-resolved,
& .icon-icon-file
color: $color1;
& .card__actions
background: linear-gradient(135deg, $color1 0%, $color2 100%);
& .gradient--light-green
@include gradient-colors(#128465, #99ca3c);
And so now you're left with:
& .gradient
height: 100%;
& .card__header
&::before
content: "";
display: inline-block;
width: 0;
position: absolute;
height: 0;
left: 0;
margin: 0 auto;
right: 0;
top: 100%;
border-style: solid;
border-width: 10px 10px 0 10px;
@mixin gradient-colors($color1, $color2)
background: linear-gradient(135deg, $color1 0%, $color2 100%);
& .card__header
background: $color1;
&::before
border-color: $color1 transparent transparent transparent;
& .icon-icon-resolved,
& .icon-icon-file
color: $color1;
& .card__actions
background: linear-gradient(135deg, $color1 0%, $color2 100%);
& .gradient--light-green
@include gradient-colors(#128465, #99ca3c);
& .gradient--dark-green
@include gradient-colors(#336666, #33bc69);
& .gradient--aqua
@include gradient-colors(#006699, #33bc99);
& .gradient--blue
@include gradient-colors(#294c95, #4abed8);
& .gradient--blue-purple
@include gradient-colors(#50278f, #4a8cd8);
& .gradient--purple
@include gradient-colors(#424c9f, #c16cf9);
& .gradient--purple-pink
@include gradient-colors(#522cae, #be4f7e);
& .gradient--purple-orange
@include gradient-colors(#ce00aa, #ffa600);
- Move all your duplicate code into a class, say
gradient
. Pick better names. A class name like
light-green
can mean anything, can be put on anything and really is not that great.I like Microsoft's (Fabric UI) method to fix this. You define your base class, say
gradient
, and then add your customizations via a subclass, saygradient--light-green
. The double hyphen helps a lot when you come across these in the wild.I don't know SASS but given my knowledge of CSS, you should be able to make a new class with all the colours removed from your class. This will be your base class. Take:
& .gradient
height: 100%;
& .card__header
&::before
content: "";
display: inline-block;
width: 0;
position: absolute;
height: 0;
left: 0;
margin: 0 auto;
right: 0;
top: 100%;
border-style: solid;
border-width: 10px 10px 0 10px;
You then just need to remove this from your other classes. Leaving something like:
& .gradient--light-green
background: linear-gradient(135deg, #128465 0%, #99ca3c 100%);
& .card__header
background: #128465;
&::before
border-color: $color1 transparent transparent transparent;
& .icon-icon-resolved,
& .icon-icon-file
color: #128465;
& .card__actions
background: linear-gradient(-45deg, #128465 0%, #99ca3c 100%);
Notice that all of these are the same. (Except
light-green
, which has a gradient with-45deg
, where all others have135deg
)Learn how to use a mixin, and make something like: (IDK if it works)
@mixin gradient-colors($color1, $color2)
background: linear-gradient(135deg, $color1 0%, $color2 100%);
& .card__header
background: $color1;
&::before
border-color: $color1 transparent transparent transparent;
& .icon-icon-resolved,
& .icon-icon-file
color: $color1;
& .card__actions
background: linear-gradient(135deg, $color1 0%, $color2 100%);
& .gradient--light-green
@include gradient-colors(#128465, #99ca3c);
And so now you're left with:
& .gradient
height: 100%;
& .card__header
&::before
content: "";
display: inline-block;
width: 0;
position: absolute;
height: 0;
left: 0;
margin: 0 auto;
right: 0;
top: 100%;
border-style: solid;
border-width: 10px 10px 0 10px;
@mixin gradient-colors($color1, $color2)
background: linear-gradient(135deg, $color1 0%, $color2 100%);
& .card__header
background: $color1;
&::before
border-color: $color1 transparent transparent transparent;
& .icon-icon-resolved,
& .icon-icon-file
color: $color1;
& .card__actions
background: linear-gradient(135deg, $color1 0%, $color2 100%);
& .gradient--light-green
@include gradient-colors(#128465, #99ca3c);
& .gradient--dark-green
@include gradient-colors(#336666, #33bc69);
& .gradient--aqua
@include gradient-colors(#006699, #33bc99);
& .gradient--blue
@include gradient-colors(#294c95, #4abed8);
& .gradient--blue-purple
@include gradient-colors(#50278f, #4a8cd8);
& .gradient--purple
@include gradient-colors(#424c9f, #c16cf9);
& .gradient--purple-pink
@include gradient-colors(#522cae, #be4f7e);
& .gradient--purple-orange
@include gradient-colors(#ce00aa, #ffa600);
answered May 10 at 9:10
Peilonrayz
24.3k336102
24.3k336102
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f194078%2fdifferent-color-classes-that-control-the-same-stuff%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password