Ready to watch this entire course?
Become a member and get unlimited access to the entire skills library of over 4,971 courses, including more Web and personalized recommendations.Start Your Free Trial Now
- View Offline
- Building a CSS-friendly workspace in Dreamweaver
- Creating style sheets visually
- Hand-coding styles
- Working with code hinting
- Organizing style sheets with color coding and sections
- Writing global classes
- Eliminating style conflicts
- Deploying styles
- Dealing with browser compatibility issues
Skill Level Intermediate
Earlier in this title, we discussed the advantage of separating the styles in your style sheets into sections. By creating separate sections for items such as layout, typography, or page regions, you create more organized files and make editing and maintaining them easier. You can take that concept a step further by creating what's known as modular style sheets. The modular style sheets are created by separating the site's CSS into individual style sheets and then reassembling them at run time. Before we discuss how to assemble style sheets at run time, let's focus on preparing our modular stylesheets by separating our styles into separate files.
So, I have the main.css open from the 04_03 folder. What we're going to do is we're going to separate out a couple of sections of styles that not every single page is going to need. We have a full set of styles for table design, and we have a full set of styles for forms. But not every page is going to be using tables, and not every page is going to be using forms. So, if that's the case, then really loading up those styles is pretty much wasted content. So, we're going to go ahead and separate that out, and then just let the site call for those styles when it needs them.
So, the first thing I'm going to do is I'm going to go up to File and choose Save As. And I'm going to save this in the 04_03/_css directory. And I'm just going to call this one global.css. So, this is going to contain the majority of our global styles. Now, before we go too far down this road, I want to talk a little bit about strategy. The reason I'm separating out the table styles and the form styles is they are pretty easy to separate. In a lot of cases, when people are creating modular styles, they'll put their layout styles in one file.
They'll put their typography in another file, their color treatment in other file. It's really up to you in terms of how you want to separate these styles out. You can separate them out like content, or you can separate them out by the type of selectors you're dealing with. Okay. So now what I'm going to do is go down and find my table styles. I'm going to scroll down all the way to around 600 -- line 698. All right! So, 683. Here we go. So, there is our data tables. We're going to go ahead and take that. so, I'm going to highlight all the way down to about line 738. There we go - just above this spotlight region. You want to make sure you'll getting that last curly brace there, too.
I'm going to go ahead and cut those. So, Command+X or Ctrl+X, so there we go. I'm going to go ahead and cut that out. Now, create a new file, and we're looking for a new CSS file. Create that. And then go ahead and paste the table styles that you just cut from your previous CSS file. We're going to go ahead and do a save on that. We want to save that in the 04_03/_css. And we're going to save this one as table _styles.css, tables underscore styles.
I am going to close that. Next, I'm going to go back into my global.css. I'm going to strip out some more styles. I'm going to go down to around line 705. I can found my form styling here. I'm just going to go ahead and highlight that all the way down, and there is a lot of form styles. Pass 900 to about 919. You can see right there the sidebar is the next divider that you have to worry about. Make sure, again, you're getting the closing curly brace, and cut that so Ctrl+X. There we go. We'll remove some of the extra space there.
And then we're going to go ahead and create a brand-new file, CSS again. We're going to paste the code that we just cut into that file. And we're going to save this as form_ styles.css and go ahead and save that, as well. Close that. Our global CSS is considerably shorter. Where it was past 1,000 lines of code before, now, it only goes out to 130, so we're saving a little bit of weight there. I do want to go back up, however, and modify table of contents.
I'm just going to go ahead and get rid of data tables, and I'm going to get rid of forms. Now, if we were doing this for real, we'd probably want to update the identifiers too, but as it is, they are fine where they are. Now, obviously we could have chosen from a variety of organizational strategies for these modular styles. By separating forms and tables, we remove hundreds of lines of code. The most were pages we don't even need. Now, we could have just as easily separated layout, typography color, any of those other groups that I was talking about, the exact same way. Well, now that we've our styles separated, we need to make sure each page in our site is getting exactly the styles that needs.
We'll do that in our next movie, as we learned to build modular styles.