Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Now that we've seen how to access a browser's web debugging tools, let's experiment with using them to troubleshoot our CSS and refine our page layout. Now, for this exercise, we're going to focus on using the two most popular web debugging tools, Web Inspector and Firebug, as a way of getting more comfortable with using the tools, but don't be afraid to use Dragonfly or Microsoft's tools, whichever browser that you're going to be using most frequently, and really should be comfortable with using all of these tools. Okay, so I have index.htm opened up here from the 01_11 folder, and the first thing I'm going to do is I'm just going to preview this in Firefox.
So, this is very common. We work on a page for a while, we save it, we test it, we preview it in the browser, and we see something that doesn't exactly look the way that it's supposed to. And in a lot of cases, we have to sort of guess why or go back in our code and figure something out. In this case, I want to use is browser debugging tools to help me figure out what's going on here. So, what's happening is this banner headline right here, We love urban photography, does not look the way that it should. We should see slightly a little bit more letter spacing and that should be all caps rather than mixed caps. So, I'm not really sure what went wrong here, so I'm going to turn on Firebug and see if it can help me with this.
So, I'm going to go right up here and turn the Firebug console on, and again just to sort of refresh your memory about Firebug, we have these different tabs which we can look at: the HTML; we can look at the CSS; we can look at any scripts that are going on; we have console view, that sort of thing. I want to focus on the HTML right now because notice that one of the things you can do is you can just sort of parse through your code and you'll see a preview of the element and you'll actually see some of the box model properties. Purple is padding, yellow margin, and then the blue that you're seeing that's the actual content itself. And we can go through and inspect any part of our code that we want.
We can open up our code structure. We can look inside these various elements, so we can really inspect all the things we want to. All right! So, going back to our banner here, we also have this little tool right here that says, "Click an element on the page to inspect." So, if I grab that, I can just sort of mouse around, visually grab the element that I want. That's going to focus on that within my code. Okay, if I look over here on the right- hand side of the Style panel, I can see the computed styles for this element. Well, the computed styles aren't what I expect them to be. Color, font-size, and padding-top, they're exactly what I expect them to be, but I'm missing a couple of properties.
I'm missing my letterspace property and I'm missing my text transform property. Now, there are a couple of things that I can do here. One of the things, for example is, I can go to the console. So, if I go over to the console and I run my warnings--now sometimes you have to refresh the page in order for this to cycle through again-- I notice that right at the very top of this it says, "Expected end of value but found ':' Error and parsing value for 'letter-spacing'. Declaration dropped." Now, it does tell me this happens on line 285, but it doesn't tell me exactly which selector this belongs to. I happen to know for a fact it belongs to the one we're looking at, but if you didn't know that, you'd still be kind of almost needle-in-a-hay-stacking this, but it does tell me that something is going on wrong here.
For example, that colon there, when it's expecting a semicolon, that's going to cause some parsing errors in my CSS. So I kind of guess that that's one of those issues. Now, there aren't that many differences between WebKit's Web Inspector and Firebug, but this is one of the bigger differences. The fact that here it's just showing me the computed styles. It's not showing me all of the properties that are actually in the CSS. It's showing just the finished computed styles. So, I want to go over to Chrome for a moment and show you kind of what happens when I look at the same element in Chrome. So, if I go right over here and I view and inspect the element for that banner headline, I get a slightly different view.
You can still parse through all the elements in the code. You still get your visual aids, but the colors are slightly different here in Chrome--or Web Inspector I should say because it looks exactly the same as Safari. We have sort of that orange color for margins. We have sort of that green color for padding. And again if we inspect an element-- here's the inspect element tool here in Web Inspector-- one of the things that Web Inspector does for us that I really like that Firebug doesn't is it gives me those CSS properties, that sort of visualization, as well as computed values as I move through the elements. So, that's really kind of nice.
Okay, but back to the task at hand. Here, I see something very different. When I look over here in the Styles pane, I can see that letter-spacing has a strike through and if I hover over this, I can see that I've got a little warning message here, and then my text transform is not applying at all. So, it's just basically parsing this as one big, huge error. So, I can tell that that's a problem. Another thing that showing all of these properties does for me is it helps me catch other types of mistakes as well. Let me show you what I mean. Now, I've got a couple of choices when inspecting elements.
One, I can come through and use the Inspect Element tool and just click on elements. I can do it that way, or I can come directly down here in the code and really sort of target exactly the element I'm looking for. Now, when I click on this heading 1 that's in the header, if I look over here in my Styles, I notice there's a strikethrough with this line-height and if I look at that, the line-height is set to 100 pixels, but there's another line-height declaration down here at 165. Now, the likely culprit here is when I was authoring the styles I probably tried the line-height at 100 pixels and didn't like it and added the line-height: 165 property to the end instead of modifying it, for whatever reason, who knows, I just forgot to go back and remove the initial line-height.
Now, what I really like about this in WebKit Inspector is well, notice it tells me this is on main.css line 185. So, very quickly and very easily, using both Firebug and Web Inspector, I found two errors in my CSS that I need to address. So, I'm going to switch back into Aptana Studio, go back into my code, and I'm going to fix those things. So, I'm going to open up, from the CSS folder here in 01_11, I'm going to open up main.css, and using the information that I got, I'm going to scroll down to around line 185.
Here we go. And I realize I don't need that line-height declaration, so I'm going to get rid of that. And then down around line 280 or so, 279 now, I can find that banner h1 rule, and here's the error, right there. So, instead of a colon, that is supposed to be a semicolon, so I'm going to change that and save it, and now I'm going to go back into my browsers and I'll refresh the page. Now, notice the change in the visual. So, we now have our text-transform is working, the letter-spacing is working, everything is happening there. And in Firefox if I look over here in Firebug, now I'm actually seeing those values.
There's the text-transform. There's the letter-spacing. I wasn't seeing that before. If I go over to Web Inspector and refresh the page, I see similar results. And if I focus on that element, I can see that those properties no longer have a strikethrough. So, we've seen how we can use Web Inspector and Firebug to debug some of our CSS, but what if you just want to sort of play around with it? What if you want to manipulate it and really see almost immediately the visual impact that you're going to have on your code? Well, that's pretty easy to do as well.
So, here I am, in Web Inspector, and one of things I want to do is I want to focus again on our heading here. So, again I can do this through HTML code, I can find this and click on it, or I could just inspect it directly on the page. Now, I've got more than just styles and computed styles available to me over here. If I come over, I have this Metrics pane, and this Metrics pane is giving me the box model properties of that particular element. You'll notice, for example, if I hover over a border, nothing shows up, margin nothing shows up. It indicates those properties don't exist for that particular element. But if I go over padding, I can visually see it; if I go over to the computed width and height, I can see that as well.
Now what's really nice about this is let's say I want to change that padding value. I can actually click right here, double-click the value, I can use arrows to go up or down and I can visually see that happen. Or I can even type in a value. Let's say I go down to say 230 and hit Return. I can kind of see what effect that's going to have on that headline, and whether I like it a little bit further down or not. Now, I'm going to switch back over to Firebug and show you pretty much how the same thing is done. So, they all have the same tools for the most part; they're just in slightly different locations. All right! Let me resize the Firebug pane here for a minute and center on our headline here.
All right! So, if I go over in this point to the Layout tab, now I really like this in Firebug. This is nice because again we get the same functionality. If we mouse over to different properties, you're going to be shown those properties. Let me zoom up a little bit so we can sort of see the padding there. There we go. But we also, in Firebug, get rulers. You can see the rulers show up on the browser now. I'm getting guidelines to show me where this is lining up. And again I can use my arrows to nudge this. I can type in a value. Let's say I type in 290 this time, and you know what? At 290, I kind of like that, and I like that a lot.
So, I might go ahead and decide to use that in my own CSS. So, if I switch back to Style and my computed style for this, you'll notice that what it did is it put the sort of in-line style directly in my HTML. Now, it's not modifying the HTML on your hard drive, or even on your server; it's just modifying this particular instance. Okay, so I like that value of 290. Now, if I want to play around the way things look, I can also edit my styles directly in this window. And I can do this in WebKit Inspector or Firebug, and in this case I'm just going to show you this in Firebug.
Notice I can click to create a new line here, and I can experiment. I can say okay, well, what if I put a border on the bottom of this and I did just a 1-pixel solid white border? And now I can preview what that looks like. I can toggle that on and off to see if I like it or not, and I can decide whether or not that particular property is for me. Now, anytime, if I add these properties, I could just go ahead and highlight those and I could copy and paste all those properties directly into my page.
So, if that's what I decided to go with, I can simply copy and paste them. I can even create brand-new rules here in Firebug or Web Inspector. So, you could even author CSS directly in the browser and then copy and paste them into your code. So, if I go back into my CSS, notice that I can come right here in the padding-top, I can go ahead and plug in that 290-pixel value that I liked so much. I can go back into my page. I can refresh that, and I can see the change that I made here in the browser. The visualization of that that I like is made.
So, in that sense, regardless of which editor you're using to write your HTML and CSS, be sure to take full advantage of these powerful tools as you begin to develop your sites.
Get unlimited access to all courses for just $25/month.Become a member
58 Video lessons · 65623 Viewers
61 Video lessons · 96394 Viewers
56 Video lessons · 110139 Viewers
82 Video lessons · 105074 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.