Start learning with our library of video tutorials taught by experts. Get started
Viewers: in countries Watching now:
In this hands-on course, James Williamson demonstrates the concepts that form the foundation of Cascading Style Sheets (CSS), including styling text, adding margins and padding, and controlling how images display. The course also explores the tools needed to work with CSS, the differences between embedded and external styles, how to use selectors to target elements, and what to do when styles conflict.
So I want to start here by opening an unstyled page in a browser. So you can go ahead and do this with me. Now although I am using Firefox, feel free to use your favorite browser. And I'm just going to go up here and open a file. And I want you to go out to your exercise file, so I am going to go out to my Desktop/Exercise Files/Chapter_01/ 01_01, and I am going to find this index.htm page in there. So I am going to go ahead and open that up, and wow, nothing really special going on here at all, or is there? You see, even though it's common to refer to a page like this as unstyled, that's not exactly accurate.
What's actually happening here is that the browser that you're using is applying its own default style sheet to the page and that results in the formatting that we are seeing here. So font that's being used, the size of the text, whether it's bold or italic, the color of the links, the space between paragraphs and headings--the browser's default styling is controlling all of that. There might be some slight differences between one browser or another, but for the most part, all desktop browsers will render elements in ways similar to what you see here.
Now browsers can take this usually a step further as well, because they usually give users the ability to change certain styling preferences as well. So really quickly I am going to go into Firefox's Preferences here and show you what I'm talking about. If I go over to the Content tab, notice that I can choose which default font I want to use, so if you don't feel like using Times, for example, if I wanted to use something different, like say Arial, I can go ahead and choose that, and you can see the page goes ahead and changes.
I can also go ahead and change the size of the text as well. If I would like it a little bit larger to help make it a little bit easier for me to read, I can go ahead and select that. It goes ahead and changes the default size of the text as well. If I go to Advanced, notice that I can deselect this check box that says Allow pages to choose their own fonts instead of my selections above. And if I do that, anything they choose here for fonts-- for proportional or monospace fonts, serif or sans-serif--it's going to override whatever the browser's default styles are.
So as a user, I have a fair amount of control over how my pages look and feel and act, and that's before I deal with any of the author's CSS styles. So I am just going to close the Preferences. So what's the point of me showing you all that? Well, to make sure that you focused on a very fundamental truth of CSS when you begin writing your styles, and it's really, really important for you to understand this: as you author your own style sheets, you're not just defining how you want the page elements to look; you are also going to be overriding the browser's default styling, so you are going to be overriding all of this.
Now if you fail to take these styles into account or forget what an element's default styling is, you might end up with some unexpected formatting or some spacing issues that become really hard to track down, because you start looking for them in your styles and they are not in your styles at all; they are coming from the default browser styles. In fact, dealing with browser-default styling has even resulted in its own technique, and it's something called a CSS reset. A CSS reset is a collection of styles that zero out the formatting from these browser default style sheets, and they help to give you a consistent point from which to begin writing your own styles.
Now if you want to learn a little bit more about those, I have a couple of sites for you to take a look at. First Six Revisions has an article. You can just go to the Six Revisions site and search for this. It's a comprehensive guide to CSS resets, and it gives you a little bit of background about CSS resets and then goes over some of the more popular ones. There is another site that I really like. This is cssreset.com. This one gives you a really quick and concise way to grab some of the code from the more popular CSS resets out there, as well as some documentation. And there's a lot of information on this site as well, about what a CSS reset is and when you should use them.
And if you want to learn a little bit more about browser's default style sheets, there's an older, but still incredibly useful collection of user agent style sheets at Jens O. Meiert's--and I hope I'm pronouncing these names right--blog. Just go to his blog and search for "User Agent Style Sheets." And he's got a whole collection of user agent style sheets. Again, these are a little bit old, but they help give you a really nice idea of what the foundation-level styles are for most of your user agents. I don't want you to worry too much about default styles; for the most part, they focus on the really basic formatting that you're likely to end up overriding anyway in the course of writing your styles.
Just be sure to pay attention to browser's default styling, and keep them in mind when planning and authoring your own styles.
There are currently no FAQs about CSS: Core Concepts.
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.