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
Debugging CSS is difficult in the first place. Good thing we have tools like the Inspector.
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
Now that we've covered all theses awesome ways of breaking code down into
-
0:03
smaller and smaller parts, and using either manifests or globbing to bring them
-
0:08
all back together again, this introduces a new problem with troubleshooting.
-
0:14
When looking at your rendered CSS in the browser's inspector,
-
0:17
seeing exactly what code is doing what is difficult.
-
0:21
The inspector will show you what line of CSS this is,
-
0:25
but not what line of Sass this is, or even what Sass file it might have come from.
-
0:30
This is a huge sad face.
-
0:33
Good news is that we have the technology to make it better.
-
0:37
Next, we'll look at how we can get a full trace from the command line and
-
0:42
explore a new way of troubleshooting, source maps.
-
0:46
Then we'll review on how you can leverage source maps in
-
0:49
the Chrome inspector to see where the code is actually coming from.
-
0:53
Last, we will look at how you can set up automated watches from the command line,
-
0:59
and use tools like grunt and gulp.
-
1:03
Debugging CSS can be difficult in the first place.
-
1:05
Good thing we have tools like the inspector to use.
-
1:08
But these tools are pretty useless when we start using Sass in a modular way.
-
1:12
So, one way to address this is to expose line numbers in your
-
1:15
output CSS's comments.
-
1:18
So, let CD into this Projects Folder here.
-
1:21
And, I am going to create a Sass file, okay?
-
1:25
And then I open the Sass file up.
-
1:31
Let's just put some simple Sass in here to get started.
-
1:33
$color: orange.
-
1:37
And then I'm gonna say, body is, background color is using $color.
-
1:46
And then I also want to do this.
-
1:52
Oops.
-
1:58
So save that.
-
1:59
Come over here.
-
2:01
So now, basically just by running Sass app as CSS, I see the output.
-
2:08
All right. But this isn't giving me
-
2:09
what I'm looking for.
-
2:11
If I do sass--help, I get a whole lot of stuff here.
-
2:16
But what I'm looking for here is line numbers.
-
2:18
So the -l flag gives me line numbers.
-
2:22
So if I do sass-l and then app.sass.
-
2:28
We see down here, and we'll bring this up a little bit.
-
2:33
We see down here that there is line 3 app.scss makes body color orange and
-
2:39
then line 7 of app.scss makes h1 color white.
-
2:43
Okay, so that's really helpful information but
-
2:44
running it in the terminal is not very helpful.
-
2:46
So let's output a CSS file, so I can do the exact same thing here.
-
2:52
So if I do Sass dash L and then I say at SCSS,
-
2:58
but then I declare an output, and I say style.css.
-
3:04
So now I created my style CSS file.
-
3:09
So if I open this up, now I see output into the CSS file is
-
3:13
those exact same line numbers that we were looking for.
-
3:17
Next, we need to view what's happening in the browser.
-
3:19
The easiest way to do this is to start a simple server using Python.
-
3:23
FYI you don't need to know anything about Python.
-
3:25
Python is already installed on your computer most likely,
-
3:28
we're just gonna start up a simple server real quick.
-
3:31
So to do this, I'm gonna open up another tab in my bash here.
-
3:36
And I'm still in this project, so
-
3:41
I'm going to type in python-m, and
-
3:47
then it's simple, oops, simple HTP server.
-
3:54
And we are now running on port 8000, okay.
-
3:58
Now I'm gonna come back to my other tab over here, and the thing that I need to do
-
4:02
is open my index file, and I need to add my h1 in here, right?
-
4:09
So, h1, oop, yep, that's what I wanted.
-
4:11
And then, Hello World.
-
4:15
Great.
-
4:17
Now, if I go over to Chrome, and I'll bring this
-
4:23
up over here, and I go to local host 8000.
-
4:28
So there's my page.
-
4:33
Okay, so now, when I inspect element, and
-
4:39
then I have the h1 selected here.
-
4:44
What I see is the output is the style.scss, or the style.css at line 6.
-
4:49
But by clicking on this, this actually takes me to the CSS file and
-
4:53
then I'm seeing what we saw before in the CSS file.
-
4:56
So this is really helpful from this perspective to debug in this way.
-
5:00
So that whenever you're actually selecting something from the inspector, and
-
5:05
then you click on this location inspector, then it takes you literally to,
-
5:09
like, the cursor setting here at line 6,
-
5:11
and it's telling me that this came from line 7, from the app.scss file.
-
5:15
And of course, if we add more files in here, then this would give me from all
-
5:19
the different files from where the Sass is actually coming from.
You need to sign up for Treehouse in order to download course files.
Sign up