Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
In this movie we're going to be discussing Naming Conventions and how you should start to rethink the way that you name things in your CSS documents. This is one of the more common questions that I get from people who are just learning CSS. They always ask, now, what do you name these things? How do you learn how to name these things? It's really up to you how you name these things and why you name things what you do, but you do need to assume that this is going to be edited at some point in the future especially if you're doing client work. Chances are they're going to come back with suggestions for your work, and you want to name things in such a way that lends itself really well to future editing.
In this case I have to find two columns, and that's here in the main body styles of the CSS document. I've got column right and column left. What if next year I have to come back in to redesign this site, and I need to move that left column to the right or that right column to left? I shouldn't have to go in and rename the element in my HTML code and in my stylesheet as well just to change the position around. Instead of using column right and column left as my declarations here, what I should've done is do something like col-a and col-b for these.
That makes a little bit easier for me to see col-a versus col-b. It's not as absolute as right and left and then all I have to do is come back in and change the float right or the float left and then in my HTML document I would already have col-a and col-b. It wouldn't be as confusing if I had one that was left, but it actually floats right and one that's on the right that actually floats left. That can get really confusing. You also need to be cognizant of the fact that you need to be naming things based on what they are and not what they look like.
So for instance, if you had a class here that said something like comment-blue. That's a very absolute thing, because the comment is supposed to be blue in theory according to that declaration name. However, that's a lot less versatile than something like comment-footer or something like that. Changing the name to comment- footer is a little bit more broad. It tells me where the comment is as opposed to what it looks like and gives me the flexibility to change the color property anytime I want without any penalty.
The same holds true if I were do something like post-largefont. What if in the future I need to shrink the size of that font, and it's not so large anymore. A better title would be something like post-title or post-body or something like that. So name things according to what they are, not what they look like. I think this is a great technique to follow and a great way to help you plan out your CSS style names so that they are more functional for you and also for the people who might working on this document even after you've produced it and set it up on the web.
Get unlimited access to all courses for just $25/month.Become a member
58 Video lessons · 59727 Viewers
61 Video lessons · 92506 Viewers
82 Video lessons · 104140 Viewers
56 Video lessons · 107007 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.
Your file was successfully uploaded.