Browsers apply default values to block level elements; unfortunately these default values are not consistent. These default values can, and do, vary greatly from browser to browser. With this in mind, we will create a CSS rule in our style sheet that will remove all the default values. This is an important first step, because without removing the default margin and padding values, the layout of the XHTML page will not display the same when viewed in different browsers. It is a best practice to always use this rule to "zero out" the default values, so that your page design is based on a standardized view, no matter which browser is used to view it. As you begin developing web pages with Dreamweaver CS3 that are formatted using CSS, remember to add this rule to every new page you create, because it may not be included in the default style sheet that is generated with your selected layout. As a general rule, removing the default properties and values inherent in the various browsers is not absolutely mandatory, although adding this rule does provide greater control. However, you must remember to specifically set margin and padding values for any page elements that require them.
To remove the default properties using the most efficient code, we will group selectors together. This is a new concept that is described in detail in the demo below. By grouping the selectors, we can create a single CSS rule that uses the wildcard selector to zero off all the default values. The wildcard selector is denoted with the asterisk symbol: *. The wildcard means "all"—which is a powerful way to refer to all page elements (body, etc.) at once. Remember that the order in which you list the rules in your style sheet is very important. The rule to remove the default values and start your design from a "zeroed out" space should always be the first rule in your CSS page. You could encounter odd display issues if the rule was placed below other rules, because when the browser "reads" the rule it would zero out all of the padding and margin values that were set in the rules that preceded it in the style sheet.
Here are the steps reviewed in the demo:
In the steps above, we used the wildcard selector to remove all the default values from all page elements. It is highly recommended that you add this rule to any new CSS page you create, because it is very helpful in eliminating issues that you may encounter when troubleshooting the display of your page layouts. Now that we’ve removed the default values and reset every element to zero, we can begin the next task: adding specific values for the margin and padding for each element, to set the desired spacing.
To achieve this goal, we’ll use the interface within Dreamweaver CS3, specifically the CSS Panel and we’ll edit the index.html page while working in Design view in the Document window.
Here are the steps reviewed in the demo:
<p> tag<p> tag rule<p> tagsIf you’d like to see the CSS rule generated by the changes made to the CSS Styles panel, look at the code in the twoColElsLtHdr.css file to see the new CSS rule for the <p> tag. It will look like this:
p {
font-size: 80%;
margin: 1.5em 0;
}
In the instructions above, we entered a value of 1.5em for margin setting for the <p> tag element. You may be wondering why the "em" measurement value was used rather than another form of measurement, such as %. The em measurement is a relative value, and it is a good practice to use the em measurement setting to ensure that the various elements on your page scale proportionately. If you’d like to see how this works, experiment with changing the font-size value, and notice how the top and bottom margins on the p element increase proportionally with the size of the text.