Join James Williamson for an in-depth discussion in this video The CSS Styles panel, part of Dreamweaver CS5 Essential Training.
The CSS Styles panel acts as the central hub for all things CSS in Dreamweaver, providing you with both a global view of all document styles, as well as allowing you to focus on individual rules and style applications. So for this exercise, I have our resources.htm file open in the 06_04 folder. Now, you are going to find the CSS Styles panel in the CSS panel Grouping. That's usually located at the top of the panel Dock, although you can reposition it in Custom Workspaces if you would like.
Now, I am going to give myself a little bit more room here by double-clicking on the Files panel tab. That will collapse that, and that will give us a full dock to work here with the CSS Styles panel, because depending upon the view you are looking at with, it can take up a lot of room. Now, at the very top of the panel, you will find buttons for two views: All and Current. The All View gives you an overview of all of the CSS Styles applied to the current document, while the Current View gives you a detailed view of the rules applied to a selected element.
Before we start creating our styles in earnest, let's take a moment to get a little bit more comfortable with finding our way around and using the CSS Styles panel. Now, if I click on All and I scroll all the way up to the top of my rules listing, I can see that I have a external style sheet link to this file. How do I know it's an external style sheet? Because it says main.css; I can see the extension. I can collapse all these rules. If you had multiple style sheets or embedded styles, you would see all of those guys listed as well. But for this particular file, we just have the one external style sheet linked.
Now, we do have some parentheses right up beside it that says, screen, projection. Those are referring to the media type for the style sheet. If I switch over to the Code View of the page, you can see, right here in this Link file, we have an attribute that says media = "screen, projection". That means that these styles are to be applied to any devices that request the screen or projection media type. So these styles wouldn't apply to screen readers or other user agents like that. I am going to switch back to Design view.
Let's take a look at specific rules. I am going to click right here in the single rule, Got questions. Now, I can see, by looking at the structure of my page and my Tag Selector, that this is inside of a <h1>, which is inside of a div with the ID of mainArticle, which is inside of a <div#mainContent>. So I can look for some specific rules that are controlling that element, however, it's a lot easier to find if I click inside that and switch over to Current mode. Current mode tells me exactly the rule that I am targeting. I am just going to expand this out a little bit, so you guys can see this a little bit better, because sometimes that's a little hard to see.
I may need to rearrange this panels a little bit. So notice that you can take the CSS Styles panel, and you can begin to move these dividers to give yourself a little bit more room. Let's examine the Current rule in a little bit more detail. The top pane gives us a Summary for the current Selection. Here we see all of the properties that are styling our currently selected content. Now, not all these properties necessarily come from the same rule. That's one of the things about CSS. You will notice that if you hover over one of the properties, it will tell you exactly which rule they are coming from. Notice that they are not all coming from the same rule.
Now, if we look down below that, we can see all of the rules that are affecting this element. I can scroll back and forth to see which rules are affecting it the most. The ones at the bottom are the most specific styles and any content set here would overwrite content set in the styles above it. Finally, down below that, if I select any of these individual rules, I get the properties for those specific rules. If I want, I could even Add Additional Properties to those. So let's say that I wanted a little bit of extra spacing down below this headline.
I could select the rule that I want to affect, in this case, #mainContent #mainArticle h1. I could just click right here to Add a Property. Now, you can grab that pulldown list, if you are not as familiar with property names, or if you know what you want to do, you could just type it in. In this case, I am going to choose margin-bottom. Just going to add a little bit of space underneath this. So I am going to type in .4 em, and that's em. So I can just type in .4 em and hit Return. That's going to increase the spacing. You can see the text here went down by just a little bit. So anytime you want, you can use the CSS Styles panel to add to an existing rule without having to go to any code or open up any additional dialog boxes.
Now, I am going to switch back to All for just a moment and talk about what types of things we can display in the All View. First off, we get all of our rules that are in our external style sheet. So a lot of times here, you have to scroll down until you find the rule that you are looking for. So if I scroll down, I can find right here, #mainContent #mainArticle h1. That's the rule that we just changed. If I click on that, I can see that now I have the same summary of the properties in that rule. I have the ability to Add Properties here as well. Well, you can change how this panel displays these rules.
If you notice in the CSS Styles panel, there are three icons in the lower left-hand corner of the All View. The first icon gives us what is known as a Category View. It's going to be a listing of all the categories, such as Fonts, Backgrounds, Block level changes, Borders, Box model. So if you are familiar with these categories, you can quickly access them and change properties directly through this Category listing. We also have a listing that Shows List View of every single CSS property that you can change, and there are a lot of them.
So if you like that view, you get a nice alphabetical list of those. Any properties that are being used and set on the rule will appear at the very top of the listing, and they are highlighted and colored in blue. Finally, we have my Favorite view. The Favorite view shows only the properties that you have set. It reduces the amount of clutter that you have to look at. That's my preferred view, and that's typically what I will do. Now, the CSS Styles panel can be used for a lot more too. Let's say we want to create a different rule. In this case, maybe we want to create a rule that's going to control this heading too. It's going to be very similar to what we had before.
So I am just going to scroll down and click inside that heading 2. I am going to go down to me CSS Styles panel, and in the lower right-hand corner, there is another set of icons. The one that has the page with the Plus symbol on it, if you hover over that, it will tell you that's a New CSS Rule. I am going to click on that. Now, we are going to cover this dialog box in a little bit more detail later on. Suffice it to say that this dialog box is going to assist you in creating your rules. In this case, notice that it automatically came up with what we call a Compound Selector, because it knows that there are a lot of factors identifying that element on the page.
So we are seeing here # wrapper #mainContent #mainArticle h2. Well, I am going to get a little less specific with it, because if you remember, our previous rule that had the h1 had the #mainContent and #mainArticle, but it didn't have wrapper, so that's not really necessary. So I am going to choose Less Specific, and that resolves itself to say #mainContent # mainArticle h2. Perfect! I can also tell Dreamweaver where to place these styles. In this case, I am going to place it in main.css, which is that external style sheet. Your other choice is to place it in (This document only), which would embed it in the head of the file.
Or you can create a brand New Style Sheet to place that in as well. I am going to leave that as main.css and click OK. Now, this is a great dialog box. What we get now is the CSS Rule Definition dialog box. This is a dialog box that's separated by Categories: Typography, Background, Block properties, Box model properties, that you can go through and set each one of those properties for this specific rule. So again, if you are not that familiar with CSS, this is a great dialog box to access, because it gives you an ability to go ahead and choose all these items for your particular element.
In this case, Font-size. I am going to click in Font-size and say 1.6 em. You can just type in em, or you can grab ems from the pulldown menu right there. So 1.6 em. For Color, I am going to type in #51341a. If you hit Tab, you can see that that's going to be that brown color that we are using throughout our site. Now, CSS can either use RGB values or Hexadecimal notation for color values. Most people use hexadecimal values, although with the advent of CSS3 and HTML5, RGB values are starting to be used in an increasing amount.
Font-weight, I am going to grab that pulldown menu and choose Normal. Most headings are Bold be default, but I want this heading to not be bold. So I am going to change Font-weight to Normal. I am also going to go down and set a couple of other properties in my Box category. The Box category is where you choose things like Padding and Margins, so it's primarily used for spacing. For Margin, I am going to deselect Same for all, and for Top Margin, I am going to type in 1.2 em. For Bottom Margin, I am going to just type in 1 em. Now, if you are curious about what an em is, we will have a movie a little bit later on that describes unit of measurements.
But an em is a unit of measurement typically used in relation to type. Finally, we are going to do one more thing that might be a little confusing for those of you who are new to CSS. We are going to grab this Clear Property, and we are going to choose Both. What that will do is it tells Dreamweaver, "Don't allow objects to float to my left or float to my right." It's basically going to make sure that this heading is on its own line and not effected by any floats that we may have replaced into our file. I am going to go ahead and click OK, and I can see right there my heading changes. Now, you will notice that it placed that rule right underneath the h1 tag.
How did it know to do that? Well, it wasn't guessing. It was the fact that I actually had the h1 rule selected in my styles before I created it. So if you want to control the placement of where your rules go, make sure you highlight the rule just above where you want it to be, although you can certainly select rules and drag them up and down the order to organize them if you would like. Now, I know it seems like we have covered a lot of ground, but to be honest, we have just scratched the surface of what we can do with the CSS Styles panel. Don't worry. You will be using the CSS Styles panel throughout the rest of this title.
That's going to give you plenty of time to familiarize yourself with those capabilities, as well as exploring some of its additional functionality a little bit later on.
- Defining and structuring a new site
- Creating new web documents from scratch or from templates
- Adding and formatting text
- Understanding style sheet basics
- Placing and styling images
- Creating links to internal pages and external web sites
- Controlling page layout with CSS
- Building and styling forms
- Reusing web content with templates
- Adding interactivity
- Working with Flash and video
Skill Level Beginner
Q: After creating a website following the instructions in the course, the header background graphic appears correctly in all browsers except Internet Explorer 6 and Internet Explorer 7. The graphic works properly in IE 8. What can be done to make the graphics appear in IE 6 and IE 7?
A: To make the header background graphic appear, wrap the header div tag in another div tag and give it an ID like “mainHeader.” The problem stems from a bug in Internet Explorer that prevents the browser from dealing with absolutely positioned elements that are right next to relatively positioned elements. Following the steps above should solve the problem.
Q: In the tutorial, the author links the Tool Tip to the word "More" at the bottom of the thumbnail photo field. I can't figure out how to place the <a> "More" on the thumbnail photo field.
If you were manually typing the text in, you could select the image, hit the right arrow button, and begin typing. The text should then appear on screen.
Q: In this movie, you are making changes to the HTML in order to customize the text layout on your page (i.e. h1, h2, and h3 tags as well as strong and em tags). I'm wondering why you are not using CSS to do this (i.e. font-size, font-weight). Do you typically use one method, or is it customary to do use both in a layout, and if so, what guidelines would you suggest to determine which to use when?
A: We modify the page's structure through the use of h1, h2, and other heading tags. So when we are choosing heading levels, we're not concerning ourselves with typography; we're establishing page structure. A heading is chosen to denote the level of importance for the heading, not typography.
CSS should always be used for presentation, not HTML.
Q: In the “Understanding ID selectors” movie, the author states that only one ID tag can be used per page, but then he adds two ID tags. Can you please clarify this for me?
A: You can use as many IDs per page as you wish. They just must all use a unique name. Therefore if you assign an element the ID of "header" no other element on THAT page may use the same ID.
Q: I noticed that in this course, the instructor uses this code on his CSS external sheet: @charset "UTF-8"; I was under the impression that this code wasn't necessary. The W3.org site is unclear on the matter. Is it necessary? Is it a best practice? Is it an older form of CSS?
A: The characterset attribute is added automatically by Dreamweaver, and there’s no practical reason to remove it. While it's not needed (the HTML page should indicate which encoding to use for the page) it is helpful if the CSS file is ever imported or used on a page where the characterset isn't specified. Think of it as a safety net for characterset encoding. Not necessary, but not harmful either.
Q: I need to add captions below images that I insert in pages of text. I played all the lessons in Chapter 5 (Adding Text and Structure) but none dealt with captions. I hope the author has an answer or can refer me to a source.
A: In HTML 4 and XHTML 1 (which is what Dreamweaver CS5 uses by default), there wasn't really a way to add captions below your photos. Most web authors would "fake" captions by having paragraphs of text below their images and using CSS to position and style the captions in the desired manner. Many would use a class such as .imgCaption to control the styling. To do this you would essentially position the text underneath the image through CSS (often by grouping the image and the paragraph in a div tag) and italicizing the text.
However in HTML5, there are new elements that allow us to associate images and their captions, the figure and figcaption element. Our author James Williamson just finished a course on HTML5: Syntax, Structure, and Semantics which details how to use it.
HTML5 Doctor also has a nice article on the figure and figcaption elements at http://html5doctor.com/the-figure-figcaption-elements/.