Start learning with our library of video tutorials taught by experts. Get started
Viewed by members. in countries. members currently watching.
Take a tour of a workflow that optimizes CSS code for easier navigation, organization, and readability. In this course, author Justin Seeley covers best practices for writing CSS in an easy-to-read format, commenting code, developing a table of contents, and adopting other methods that help produce "cleaner" code. The course also contains tips for speeding up development with some online tools and simplification techniques.
One of the things that get some people in trouble when they are developing CSS is the fact that they start to use unnecessary classes when they are developing their CSS. Chances are you are going to be doing things that you are going to find, you use certain styles that you are applying over and over and over again. For instance, you might have stuff that floats to the left, or stuffs that floats to the right. And chances are you are going to be declaring different classes of items, and you are just going to say okay, I want this to float left, I want this to float left, I want this to float right, and et cetera, et cetera. But why not just develop your own set of generic classes called .left, .right or whatever, and then use those as a secondary class when you are defining something.
So for instance, let us go in and create a new document here, and I will show you exactly what I mean by this. The first that people do when they start defining stuff, so they will do something like button-left, and then they will tell that to float:left. And then they will do something like column-left, and then they will tell that to float:left. Again, it's just more redundancy that you don't need, you don't necessarily need a column-left or a button-left. You might need a button class, you might need a column class.
You might also need a left or right class, but you don't need individual columns for this. Or you might even see people do something like this, column-left-blue, or button-left-blue, and you would see something that says button-left-red, button-left-whatever. And so you grind up with all of these unnecessary classes where you could just do something like .button. And so this could be something like, you know, webkit-border-radius:6px, border-radius:6px and six pixels for that. And so that's just your button class.
And then you can have something here like generic classes that will be like .green, which is background:green.
And then you can have something like .left which you just float:left and then .right
which would just be float:right.
And so you can make up these generic classes and then when you go in, and you are defining
something in HTML, let' just create a blank HTML document, you would do something like
And so that way it absorbs the button class, the green class, and the left class all at one time, and you can also go back, and you can make changes to the button class by itself. You can make changes to the green class, the left class or right class just makes it a little bit more organized, keeps these things as generic as possible. Remember you want to design your CSS based on what something is not what it looks like. And so in this case, I am just defining the basic properties of the border-radius to maybe a width and height value. Whereas the green, the left, the right, that's all controlled generically.
That way, if I wanted to have something later on that's like a column, and we will do .column-a
here, and I can just say I want this to be 90% of the width, so let us do width:90%,
and then whether or not it floats left or right is irrelevant, because I can then go
over to my HTML document, and I can say something like,
It's using the column-a class it's also using the right class, and I didn't have to tell this to float right, I just said to tell it how wide it needs to be. So in this case, I am avoiding these unnecessary tags by developing a set of generic tags that I can then apply to different classes in my HTML markup later on. So go through, find some commonalities between things, like whether or not it floats left, it floats right, colors, et cetera. Develop yourself some generic tags that you put somewhere in your CSS document. Maybe even have your own section of quote generic tags, and so you use those generic classes to apply them to different things like buttons and columns and so forth.
I think you will find this as a great way to help you keep yourself organized and a great way to help avoid unnecessary class creation and unnecessary tag usage as well.
There are currently no FAQs about CSS: Visual Optimization.
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.