Referencing CSS is the first step in adding styles to your web projects. In this video, learn how to update your project and run a test to make sure everything works.
- [Instructor] Let's go back to the editor and create a new file. This will be for our CSS. I like to use keyboard shortcuts so I'm going to create a new file by pressing command N. Our control N if you're on a PC. And then I'll save it with another keyboard shortcut command S. You can name this file anything you want. But some common conventions are simply calling it styles, global or even the project name like resume. I'm going to stick with styles. Just make sure that you save it with a dot CSS a file extension.
And also make sure to save it within your CSS resume folder. Once you save it, you should see it appear in your left-hand panel. The next step is connecting it to the HTML file. And we're going to stick with the recommended external method. To do so we'll add in our link tag. This link tag needs to be added within the head. It doesn't really matter where you put it but I prefer to add it just before the closing head tag.
This is also a void element. So it doesn't need a closing tag. You do need to add the two attributes. Rel for relationship. And the href attribute to link to the actual file. Since our styles.css file is in the same folder as index.html, we can link directly to it by adding the file name.
And save the file. Now let's do a quick test just to make sure that the files are linked together properly. I'll be going over the syntax for CSS in an upcoming lesson. But for now let's just add this little snippet to your CSS file to change the background color of the entire page. Let's start with body to select the entire webpage. Then add in the left and right curly brackets. Tab it in once.
And add the background property. Colon. And pick any common color you'd like. Blue, green, red, yellow. Most common colors should work. I'm going to go with light blue. And end it with a semicolon. Now save this file. And let's check in the browser. If you see your background color, then that means your files are linked properly. Refresh the browser to see your changes. I see my light blue background color.
So that means my files are linked properly. If you don't see your color change, double check the CSS syntax in your CSS file. It should look like this. Make sure to check for the curly braces. And that the colon and the semicolon are in the correct places. If your CSS syntax looks good, double check that you've linked to your style sheet properly. Once you see your background color changed, then that means you're all good and ready to move on the the next lesson.
- Creating a CSS file
- Writing basic selectors
- Setting properties
- Using different typefaces and web-safe fonts
- Understanding cascading and inheritance
- Setting a font family, font size, text color, and more
- Understanding the box model
- Using the float property