This course will be retired on March 24, 2020.
Bummer! This is just a preview. You need to be signed in with a Pro account to view the entire video.
Start a free Basic trial
to watch this video
More color functions to help you never use a Hex value ever again!
You'll be working in Sassmeister for this course.
Like what you see and want to read more? Check out 'Sass in the Real World' for more on Advanced Sass!
-
0:00
Okay, so the next thing that I need to do, is that I wanna create a border, right?
-
0:05
Now what I want the border to be,
-
0:07
is that I want it to be the same color as the button, but slightly darker.
-
0:12
In Sass color functions, there's the Darken function.
-
0:16
So I can create my one pixel solid border.
-
0:18
But in, to create the color, I'm gonna use the darken function.
-
0:21
I'm gonna pass in a color, and then make it darker by 10%.
-
0:25
I can do the same thing with the text shadow.
-
0:28
[SOUND] Except I'm gonna do that by 20%.
-
0:33
So again using the blue that's being passed into it, and
-
0:36
then creating all of the other colors around it.
-
0:39
So if I were to, basically come up here and then say I want alert, I could pass
-
0:44
this in as a color, right, because this is an argument that can be consumed.
-
0:49
And so then now, I have this orangish, reddish button, right?
-
0:52
But then the highlights are, the border and then the shadow.
-
0:56
Are basically derivatives of that original color, not just black, 'kay?
-
1:00
So you can kinda makes it a little bit more realistic.
-
1:04
So if you remember from the previous example,
-
1:06
the first thing that there basically was some highlights around this thing.
-
1:10
There was a highlight across the top.
-
1:12
And then there was some shadows along, along the side okay?
-
1:16
So how we do this, is that I need to create a few more variables that we're
-
1:20
gonna pass into this thing right here.
-
1:22
Let's clean this up here.
-
1:24
And do this.
-
1:25
So then, here are my new variables.
-
1:28
So I need to create a highlight color.
-
1:30
And the highlight color I wanted to lighten by 50%,
-
1:33
so I want it to be that original color but just a little bit lighter by 50%.
-
1:36
Now, the shadow color is interesting cuz I'm gonna actually chain together,
-
1:42
two color functions at the same time.
-
1:45
So I want the transparent ties.
-
1:47
To basically take that other color, turn it into an arch RGBA value and
-
1:51
actually you know, lower its opacity by 0.1.
-
1:54
But then I wanna turn this whole thing into a gray scale value,
-
1:57
because I do want it to be closer to black than it is to the original color.
-
2:01
I don't want, if you put in like, pink, I don't want it to be a pink shadow.
-
2:05
You know what I mean, so this is one that I, I actually wanna consume that
-
2:08
original color and get it more closer to a grayscale.
-
2:11
So then how we actually use these things here is I'm gonna use
-
2:14
the box shadow CSS attribute.
-
2:17
[SOUND] So getting this in here, I'm gonna use the box shadow, you know, 0, and
-
2:22
then I'm using the m function in here, and I can actually.
-
2:25
Bring that back down to 0.
-
2:28
And them I'm gonna pass in the shadow color.
-
2:30
So as we see down here, I have that original color which is passed in here.
-
2:35
Let's even change this again to I like success.
-
2:40
[SOUND] Success is good.
-
2:41
Nope, I want success.
-
2:44
Success is better, all right.
-
2:47
So, I have the green highlight for the border.
-
2:50
I have the, the slightly greenish text shadow,
-
2:53
and then I have a pretty gray scale box shadow.
-
2:56
Again, this is being derived a single color.
-
2:59
None of these x values have ever been written by me.
-
3:02
'Kay?
-
3:04
So now the last thing we need to do,
-
3:05
is we need to have that hover state in here, right?
-
3:08
So I'm actually gonna put that hover state inside of my flat button, like so.
-
3:15
So then this becomes part of the mix-in as it's included in to the selector.
-
3:19
So when I come down here, we have our slightly green, slightly darker green,
-
3:24
hover state, all right?
-
3:26
Good stuff, huh?
-
3:27
That's almost getting a little bit too, let's make that 5%.
-
3:30
Change that again, come down here, that feels a little bit better.
-
3:34
All right, that's great.
-
3:35
That's good stuff.
-
3:37
So there we have it.
-
3:38
You know? I basically created a mix-in,
-
3:41
that consumes another mix-in that has a bunch of
-
3:44
great default values that we can change.
-
3:47
You know, if I come in here and
-
3:50
then I say I want my line height to be, [SOUND] I don't know, 64.
-
3:54
You know, I get a taller button, and this is gonna change for all of the buttons.
-
3:58
Let's turn that back to 32.
-
4:00
You know, and then say I have a button padding of 10,
-
4:04
I want to make it a little bit thinner.
-
4:07
You know, we can do that as well from here.
-
4:09
So again, you know, there's a lot of things that we can do that makes this,
-
4:13
this the CSS very configurable very reusable and it wouldn't be
-
4:17
uncommon to basically take something like and put it into an individual library.
You need to sign up for Treehouse in order to download course files.
Sign up