SASS mixin for a font-awesome before/after usage
up vote
2
down vote
favorite
In my SASS I use font-awesome declarations all over the place. I'm in love with it. I've created a SASS mixin for the usage:
I started with the following:
@mixin font-awesome-icon($type, $unicode, $size, $margin, $color, $weight) {
@if $type == 'after'{
&:after {
content:$unicode;
font-family:"FontAwesome";
font-size:$size;
color:$color;
font-weight:$weight;
margin:$margin;
@content;
}
}
@if $type == 'before' {
&:before {
content:$unicode;
font-family:"FontAwesome";
font-size:$size;
color:$color;
font-weight:$weight;
margin:$margin;
@content;
}
}
}
I then scaled it down further to the following:
@mixin font-awesome-icon($type, $unicode, $size, $margin, $color, $weight) {
$beforeOrAfter:'';
@if $type == 'after' {
$beforeOrAfter:'after';
}
@else if $type == 'before' {
$beforeOrAfter:'before';
}
&:#{$beforeOrAfter} {
content:$unicode;
font-family:"FontAwesome";
font-size:$size;
color:$color;
font-weight:$weight;
margin:$margin;
@content;
}
}
The usage would something like:
.tater {
@include font-awesome-icon(before,'f0de',2.1em,0 0 0 3em,orange,300);
}
But I feel I could make the before/after part cleaner. I basically need to determine if it is a 'before' or 'after'.
css sass mixins
add a comment |
up vote
2
down vote
favorite
In my SASS I use font-awesome declarations all over the place. I'm in love with it. I've created a SASS mixin for the usage:
I started with the following:
@mixin font-awesome-icon($type, $unicode, $size, $margin, $color, $weight) {
@if $type == 'after'{
&:after {
content:$unicode;
font-family:"FontAwesome";
font-size:$size;
color:$color;
font-weight:$weight;
margin:$margin;
@content;
}
}
@if $type == 'before' {
&:before {
content:$unicode;
font-family:"FontAwesome";
font-size:$size;
color:$color;
font-weight:$weight;
margin:$margin;
@content;
}
}
}
I then scaled it down further to the following:
@mixin font-awesome-icon($type, $unicode, $size, $margin, $color, $weight) {
$beforeOrAfter:'';
@if $type == 'after' {
$beforeOrAfter:'after';
}
@else if $type == 'before' {
$beforeOrAfter:'before';
}
&:#{$beforeOrAfter} {
content:$unicode;
font-family:"FontAwesome";
font-size:$size;
color:$color;
font-weight:$weight;
margin:$margin;
@content;
}
}
The usage would something like:
.tater {
@include font-awesome-icon(before,'f0de',2.1em,0 0 0 3em,orange,300);
}
But I feel I could make the before/after part cleaner. I basically need to determine if it is a 'before' or 'after'.
css sass mixins
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
In my SASS I use font-awesome declarations all over the place. I'm in love with it. I've created a SASS mixin for the usage:
I started with the following:
@mixin font-awesome-icon($type, $unicode, $size, $margin, $color, $weight) {
@if $type == 'after'{
&:after {
content:$unicode;
font-family:"FontAwesome";
font-size:$size;
color:$color;
font-weight:$weight;
margin:$margin;
@content;
}
}
@if $type == 'before' {
&:before {
content:$unicode;
font-family:"FontAwesome";
font-size:$size;
color:$color;
font-weight:$weight;
margin:$margin;
@content;
}
}
}
I then scaled it down further to the following:
@mixin font-awesome-icon($type, $unicode, $size, $margin, $color, $weight) {
$beforeOrAfter:'';
@if $type == 'after' {
$beforeOrAfter:'after';
}
@else if $type == 'before' {
$beforeOrAfter:'before';
}
&:#{$beforeOrAfter} {
content:$unicode;
font-family:"FontAwesome";
font-size:$size;
color:$color;
font-weight:$weight;
margin:$margin;
@content;
}
}
The usage would something like:
.tater {
@include font-awesome-icon(before,'f0de',2.1em,0 0 0 3em,orange,300);
}
But I feel I could make the before/after part cleaner. I basically need to determine if it is a 'before' or 'after'.
css sass mixins
In my SASS I use font-awesome declarations all over the place. I'm in love with it. I've created a SASS mixin for the usage:
I started with the following:
@mixin font-awesome-icon($type, $unicode, $size, $margin, $color, $weight) {
@if $type == 'after'{
&:after {
content:$unicode;
font-family:"FontAwesome";
font-size:$size;
color:$color;
font-weight:$weight;
margin:$margin;
@content;
}
}
@if $type == 'before' {
&:before {
content:$unicode;
font-family:"FontAwesome";
font-size:$size;
color:$color;
font-weight:$weight;
margin:$margin;
@content;
}
}
}
I then scaled it down further to the following:
@mixin font-awesome-icon($type, $unicode, $size, $margin, $color, $weight) {
$beforeOrAfter:'';
@if $type == 'after' {
$beforeOrAfter:'after';
}
@else if $type == 'before' {
$beforeOrAfter:'before';
}
&:#{$beforeOrAfter} {
content:$unicode;
font-family:"FontAwesome";
font-size:$size;
color:$color;
font-weight:$weight;
margin:$margin;
@content;
}
}
The usage would something like:
.tater {
@include font-awesome-icon(before,'f0de',2.1em,0 0 0 3em,orange,300);
}
But I feel I could make the before/after part cleaner. I basically need to determine if it is a 'before' or 'after'.
css sass mixins
css sass mixins
edited Jun 24 at 4:44
200_success
127k15148411
127k15148411
asked Feb 23 at 16:07
HollerTrain
1163
1163
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
The $type
can be passed in directly to the pseudo-class selector after you check its validity.
@if $type == 'after' or $type == 'before' {
&:#{$type} {
content:$unicode;
font-family:"FontAwesome";
font-size:$size;
color:$color;
font-weight:$weight;
margin:$margin;
@content;
}
}
add a comment |
up vote
0
down vote
I'm not as familiar with SASS, but why not pass $type directly:
&:#{$type} {
content:$unicode;
font-family:"FontAwesome";
font-size:$size;
color:$color;
font-weight:$weight;
margin:$margin;
@content;
}
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
The $type
can be passed in directly to the pseudo-class selector after you check its validity.
@if $type == 'after' or $type == 'before' {
&:#{$type} {
content:$unicode;
font-family:"FontAwesome";
font-size:$size;
color:$color;
font-weight:$weight;
margin:$margin;
@content;
}
}
add a comment |
up vote
1
down vote
The $type
can be passed in directly to the pseudo-class selector after you check its validity.
@if $type == 'after' or $type == 'before' {
&:#{$type} {
content:$unicode;
font-family:"FontAwesome";
font-size:$size;
color:$color;
font-weight:$weight;
margin:$margin;
@content;
}
}
add a comment |
up vote
1
down vote
up vote
1
down vote
The $type
can be passed in directly to the pseudo-class selector after you check its validity.
@if $type == 'after' or $type == 'before' {
&:#{$type} {
content:$unicode;
font-family:"FontAwesome";
font-size:$size;
color:$color;
font-weight:$weight;
margin:$margin;
@content;
}
}
The $type
can be passed in directly to the pseudo-class selector after you check its validity.
@if $type == 'after' or $type == 'before' {
&:#{$type} {
content:$unicode;
font-family:"FontAwesome";
font-size:$size;
color:$color;
font-weight:$weight;
margin:$margin;
@content;
}
}
answered Aug 23 at 14:13
Adam
2416
2416
add a comment |
add a comment |
up vote
0
down vote
I'm not as familiar with SASS, but why not pass $type directly:
&:#{$type} {
content:$unicode;
font-family:"FontAwesome";
font-size:$size;
color:$color;
font-weight:$weight;
margin:$margin;
@content;
}
add a comment |
up vote
0
down vote
I'm not as familiar with SASS, but why not pass $type directly:
&:#{$type} {
content:$unicode;
font-family:"FontAwesome";
font-size:$size;
color:$color;
font-weight:$weight;
margin:$margin;
@content;
}
add a comment |
up vote
0
down vote
up vote
0
down vote
I'm not as familiar with SASS, but why not pass $type directly:
&:#{$type} {
content:$unicode;
font-family:"FontAwesome";
font-size:$size;
color:$color;
font-weight:$weight;
margin:$margin;
@content;
}
I'm not as familiar with SASS, but why not pass $type directly:
&:#{$type} {
content:$unicode;
font-family:"FontAwesome";
font-size:$size;
color:$color;
font-weight:$weight;
margin:$margin;
@content;
}
answered Feb 23 at 17:31
Pslice
586
586
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f188203%2fsass-mixin-for-a-font-awesome-before-after-usage%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown