Chapter 4. Understanding Web Design

In This Chapter

  • Understanding Web design and layout options

  • Exploring HTML and XHTML

  • Styling Web pages with CSS

In the early days of the Web, designers were limited to a few simple page layout options — you could center your text and images, or leave it all aligned to the left. As HTML evolved, creating great, more complex Web designs became possible, but finding the best solution became a lot more confusing.

If you've done any Web design in the past, you may have used tables, frames, or layers to create page layouts. Today, all those options are considered outdated and are generally no longer recommended except in very special cases.

Today, most professional designers agree that the best way to create a Web page design is to use XHTML (eXtensible HyperText Markup Language, a strict form of HTML) with Cascading Style Sheets (better known by the acronym CSS).

If you're starting to worry that this book is getting a lot more technical than you expected, relax. I assure you, you don't need to learn any advanced programming to create a Web site with the templates included with this book. That said, I find that many people like to know more about how all this works, and that's what this chapter is about — helping you better understand the choices, why CSS is better than almost any other design option and how CSS and XTHML work together.

Note

If you're ready to dive in and start building your Web site right away, feel free to jump ahead to the chapter and templates for the site design you want to create. You can always come back here for more details later.

HTM-what? Exploring HTML and XHTML

Contrary to popular belief, HTML isn't a programming language. Rather, it's a mark-up language: That is, HTML is designed to "mark up" a page, or to provide instructions for how a Web page should look. HTML is written by using tags, markup instructions that tell a Web browser how the page should be displayed. For example, to make a section of text italic, you use the HTML tag <em>, which stands for emphasis. Most tags in HTML include both an opening tag and a close tag, indicated by the forward slash /. Thus, to make the name of this book appear in italics, I would write the code like this:

<strong>Web Sites Do It Yourself For Dummies.</strong>

XHTML is a more strict version of HTML that is the recommended language to use to meet the highest standards of Web design today. Among the differences between the two languages, XHTML must be written in lowercase letters; in HTML, it doesn't matter whether tags are upper or lowercase. Similarly, XHTML requires that all tags include a close tag (more on that later in this chapter.) Rest assured all templates and code examples in this book follow the XHTML standard.

To see what the code behind a Web page looks like in most browsers, choose View

Building, testing, and publishing a Web site

Tip

Split view in Dreamweaver is a useful way to keep an eye on what's going on behind the scenes and, as a bonus, you can learn a lot of XHTML as you go along.

Dreamweaver offers three view options:

  • Code: In Code view, you see only the XHTML and other code.

  • Split: In Split view, the page is divided so you can see the code in one part of the workspace, and a view of the how the page should be displayed in a Web browser in the other part.

  • Design: In Design view, you only see the page as it should be displayed in a Web browser.

In Dreamweaver's Split view, Code and Design views are completely integrated, so if you select something in Design view, like the headline you see in Figure 4.1, the same text is highlighted in Code view, making it easy to find your place in the code.

If at first glance you think that XHTML code looks like hieroglyphics, don't give up too quickly. With just a little training, you can start to recognize at least some common tags, like the <h1> tag (heading 1 tag) that was used to format the headline on the page shown in Figure 4.2.

Tip

To help distinguish the code in a Web page from the text, Dreamweaver displays the tags in a contrasting color, usually blue. You can change the size, color, font, and other features of the code in Dreamweaver's preferences.

Use the Split view option in Dreamweaver to display the page design and the code behind the page.

Figure 4.1. Use the Split view option in Dreamweaver to display the page design and the code behind the page.

A heading 1 tag highlighted in Dreamweaver Code view.

Figure 4.2. A heading 1 tag highlighted in Dreamweaver Code view.

A few points to help you better understand XHTML:

  • In XHTML, all tags must include the closing slash. A few tags can stand alone, such as the <br /> tag, which adds a line break. XHTML tags must have a closing tag, even if there is only one tag, and close tags always contain a forward slash (/). As a result, the line break tag in HTML looks like <br>, but in XHTML, it looks like <br />.

  • XHTML includes many tags that are designed to be hierarchical. Examples are the <h1> through <h6> (heading 6) tags, which are ideally suited to formatting text according to its importance on a Web page. Reserve the <h1> tag for the most important text on the page, such as the top headline. <h2> is ideal for subheads or secondary headings, <h3> for the third level of headings, and so on. A headline formatted with the <h1> tag looks like this:

    <h1>This is a headline</h1>
  • Some tags are more complex, and the open and close tags don't always match. More complicated tags, such as the tags used to create links or insert images into pages, are more challenging to use because they include link information, and the close tag doesn't always match the open tag. For example, the code to create a link to another Web site looks like this:

    <a href="http://www.digitalfamily.com">This is a link to DigitalFamily.com</a>

Note

At its heart, XHTML is just text, and believe it or not, you can write XHTML in a plain-text editor as simple as Notepad, SimpleText, or TextEdit. If you ever try it, however, you have to be careful to type all the code perfectly because there is no room for error or typos in XHTML. After writing code yourself, even to create a simple page, you're sure to quickly appreciate programs — such as Dreamweaver — that write the code for you.

One of the great advantages of using Dreamweaver is that you can specify formatting by clicking buttons or using menu commands, and Dreamweaver takes care of writing the XHTML code for you. For this and many other reasons, I chose to use Dreamweaver in this book.

Tip

If you prefer to use Expression Web, a similar program created by Microsoft, you can apply most of the instructions in this book to that program, although some of the menu items and other features are located in different places. If you do choose to use Expression Web, you can download specially created templates and instructions for creating all the template designs in this book on the companion Web site at www.DigitalFamily.com/diy.

Comparing Tables, Frames, and Layers

If you've already done a little Web design, you may be wondering what happened to some of the old ways of creating Web page layouts. For years, Web designers used the HTML feature called Tables to create page layouts. Then, Frames came along, and many people were excited by the ability to display multiple pages in one browser window, which is possible when using Frames and iFrames. Then came Layers, which were especially popular among designers because they seemed to offer precise design control.

Over the years, all these options have become less desirable except in a few special cases. In this section, you find a quick review of when Tables, Frames, and Layers may still be useful.

Creating page designs with HTML Tables

In the early days of Web design, most page layouts on the Web were created with tables. By merging and splitting table cells, and even adding background images, you can create complex Web designs with tables. CSS expands upon this concept by adding many new design options, including the ability to precisely add margins and padding around elements, and better control how and where background images appear.

Cascading Style Sheets, better known by the acronym CSS, also enables you to keep formatting information separate from content, making it possible to use less code and create pages with smaller file sizes that download more quickly. Using CSS also makes pages easier to update because you can change formatting in a more streamlined way. You can read more about CSS in the upcoming section, "Designing with Cascading Style Sheets."

Figure 4.3 provides an example of an old-school site created with the HTML table tag. To help you appreciate how this page was created, I altered the original design to display the table borders although most designers turn off table borders when using tables to create cleaner layouts. Setting the table border to 0 (instead of 2 as I did here to show you the borders), makes it possible to turn off the border of a table so that it doesn't interfere with the design.

Tip

If you visit the site at www.chocolategamerules.com, you can see how this same page was created using div tags and CSS. (I explain how div tags work within CSS in "Designing with Cascading Style Sheets" later in this chapter.)

In the old days, the only way you could create a complex Web page design was to use an HTML table to control text and image placement.

Figure 4.3. In the old days, the only way you could create a complex Web page design was to use an HTML table to control text and image placement.

Although tables are no longer recommended for creating page layouts, they're still considered the best way to format tabular data like you'd find in a spreadsheet program. That means that you can use tables to format a consistent collection of information, such as the photos and names in the list of winners from the Chocolate Game Rules site shown in Figure 4.4.

Although I recommend that you redesign sites like the one shown in Figure 4.3 with CSS and div tags, I do understand that many designers still find it easier to create layouts with tables, and not everyone has time to redesign their Web sites right away. I have to admit, I've been guilty of leaving a few sites online designed with tables long after I knew better. That said, I recommend using only CSS today for all your Web page layouts except when you are creating a layout for tabular data. Even then, I still urge you to use CSS to add any styling, such as background colors or padding, that you might want in your tables.

Tables are still considered the best way to display tabular data like the information on this contest pag.

Figure 4.4. Tables are still considered the best way to display tabular data like the information on this contest pag.

Considering design options with HTML frames

You won't find any instructions in this book for creating Web sites that use frames, such as the Pink Flamingos site shown in Figure 4.5. Frames enable you to display multiple Web pages in one browser window. Among Web designers, Frames are a little like those plastic pink flamingos stuck in the front yards of so many homes in South Florida; some people love how kitsch they are, and others just think they are tacky. Although Frames are still used on the Web, most designers don't like them because they can make navigation confusing.

Warning

Frames are also problematic because when you use frames, the URL at the top of a Web browser does not change, even when you click links and change the pages displayed within frames. As a result, you can only bookmark, or create a link to, the first page of a site that uses frames. Worse yet, frames make it harder for search engines to index a site properly, which can diminish your search engine ranking.

Frames enable you to display multiple Web pages in one browser window.

Figure 4.5. Frames enable you to display multiple Web pages in one browser window.

Using Layers (or AP Divs) to create designs

Dreamweaver MX, MX 2004, and 8 had a button for the layer feature, and it offered an easy way to click and drag boxes using divs that were positioned with precision on a page. In later versions of Dreamweaver, the name was changed to AP Divs. Divs are simply XHTML tags that serve as dividers in a page. Essentially, they create boxes around content that make it easier to position sections of text or images independently. Don't be confused by the fact that I (and most other Web designers today) recommend using Div tags with CSS to create your page layouts. We just don't recommend that you do so with the AP Divs.

AP Divs, as the name implies, are Div tags that include styling information that adds absolute positioning. That means that when you place an AP Div in a Web page, it stays where you put it, no matter how much space you have in the browser window. That may seem like a good idea at first, and AP Divs were popular among some designers for a while because they are so easy to use and so similar to many of the features in desktop publishing programs (such as Adobe InDesign). But because layers create such inflexible layouts, they don't adapt well to the changing environment of the Web where different sized monitors and other display variations can lead to text getting cut off and other undesirable results.

To cut down on the confusion caused by the term layers, Adobe changed the name of this feature from layers to AP Divs (short for Absolutely Positioned Div tags) in later versions of Dreamweaver, including CS3 and CS4. Many designers use AP Divs on occasion to add fixed position elements to a layout, but creating an entire design with this feature is no longer recommended.

Designing with Cascading Style Sheets

The concept of creating styles has been around since long before the Web. Desktop publishing programs (such as Adobe InDesign) and even word processing programs (such as Microsoft Word) have long used styles to manage the formatting and editing of text on printed pages. When using styles in a word processor, you can create and save styles for common features, such as headlines and captions. In print design, styles are great timesavers because they enable you to combine a collection of formatting options (such as Arial and bold and italic) into one style and then apply all those options at once to any selected text in your document by using only a single style. The advantage is that if you change a style, you can automatically apply the change everywhere you've used that style in a document.

On the Web, you can do all that and more with CSS because you can use style sheets for even more than just text formatting. For example, you can use CSS to create styles that align images to the left or right side of a page, add padding around text or images, and change background and link colors. You can even create more than one style sheet for the same page — say, one that makes your design look good on computers, another for cellphones, and a third for a printed page.

For all these reasons (and more), CSS has quickly become the preferred method of designing Web pages among professional Web designers. One of the most powerful aspects of CSS is how you can use it to make global style changes across an entire Web site. Suppose, for example, that you create a style for your headlines by redefining the <h1> tag to create large, blue, bold headlines. Then one fine day, you decide that all your headlines should be red instead of blue. If you aren't using CSS, changing all your headlines could be a huge undertaking — a matter of opening every Web page in your site to make changes to the font tags around your headlines. But, if you're using CSS in an external style sheet, you can simply change the style that controls the headline in the style sheet, and voilà! Your headlines all turn red automatically. If you ever have to redesign your site (and believe me, every good site goes through periodic redesigns), you can save hours or even days of work if you created your design with CSS.

Appreciating the advantages of CSS

A Web site designed with CSS separates content from design. Keeping the site content (such as the text and headings) separate from the instructions that tell a browser how the page should look benefits both the designers and your site visitors:

  • CSS simplifies design changes. For example, instead of formatting every headline in your site as 24-point Arial bold, you can create a style for the <h1> tag that contains all the formatting information in one place and then apply that style to the text in an XHTML file. CSS styles can be saved in the header section at the very top of an XHTML page, or they can be saved in a separate file that can be attached to multiple XHTML pages. One of the advantages of styles is that if you can use the same style to format many headlines and then you decide later that you want all your headlines to use the Garamond font instead of Arial, all you need to do is change the style for the <h1> tag once, and it automatically applies everywhere you've used the <h1> tag to format your headlines.

  • Separating content from design enables you to create different style sheets for different audiences and devices. In the future, separating content from design is likely to become even more important as a growing number of people view Web pages on everything from giant, flat-screen monitors to tiny, cellphone screens. One of the coolest features in Adobe Dreamweaver is Device Central, where you can preview your page designs in a variety of handheld devices and cellphones to see just how different they can look when displayed on these small screens.

    As you get more advanced with CSS, you can even create multiple style sheets for the same Web page. For example, you can create one that's ideally suited to a small screen like the one shown in Figure 4.6, another one that works best when the page is printed, and yet another designed with a larger font size for anyone who may have trouble reading the small print that is so common on Web pages.

  • Using CSS makes your site comply with the current standards. Today, the W3C, which sets standards for the Internet, recommends using CSS for nearly every aspect of Web design because the best CSS designs are accessible, flexible, and adaptable.

    Designing Web pages with CSS can help you create designs that display well on large or small screens.

    Figure 4.6. Designing Web pages with CSS can help you create designs that display well on large or small screens.

  • Web sites designed in CSS are accessible to more visitors. Today, there's a growing movement among some of the best designers in the world to get everyone to follow the same standards, create Web sites with CSS, and make sure they're accessible to everyone.

    When Web designers talk about accessibility, they mean creating a site that can be accessed by anyone who might ever visit your pages — and that includes people with limited vision who use special browsers (often called screen readers) that read Web pages aloud, as well as many others who use specialized browsers for a variety of other reasons.

    If you work for a university, a nonprofit, a government agency, or a similar organization, you may be required to create accessible designs. In Chapter 6, you find instructions for you alternative text with images and other features that can improve Web site accessibility. Even if you're not required to design for accessibility, it's still good practice because pages that meet accessibility standards also tend to score better in search engines because they're designed in a way that makes it easy for search engines to access and interpret their content.

Combining CSS and XHTML

Most professional Web designers today recommend creating Web page designs by combining XHTML and CSS. How the two work together can get a bit complicated, but you essentially:

  1. Use XHTML to create the structure of a page with tags, such as division (div), heading (h1, h2), and paragraph (p).

  2. Create styles in CSS that specify the size of these elements, where they appear on a page, and a variety of other formatting options.

Similarly, you use XHTML to insert images and create links, and then add styles to change formatting options, such as removing the underline from your links or changing the color that appears when someone rolls a cursor over a link.

Tip

All the templates featured in this book are written in XHTML and formatted with CSS following modern Web standards. In Chapters 79, you can find specific instructions for using Adobe Dreamweaver to edit the templates and customize them. I did everything I can to make these templates as versatile — and easy to use — as possible, but the more you understand about CSS and XHTML, the better you can customize the templates without changing them in a way that violates current standards or that will cause them to not display well in most Web browsers.

Creating page layouts with CSS and XHTML

The key to understanding how CSS works in page layout is to think in terms of designing with a series of infinitely adjustable containers, or boxes. Indeed, this approach to Web design is commonly referred to as the box model. Think of the box model this way: First you use HTML tags, such as the <div> (division) tag or <p> (paragraph) tag, to create a box around your content. Then you use CSS to style each box, using attributes to control the position and alignment of each box, and specify such settings as margins, padding, and borders.

Although you can use any XHTML tag as part of your page layout, the <div> tag is used most often to create the boxes for main sections of a page, such as the banner area, main content area, sidebars, and footer of a page. Think of <div> as a generic container — designed to hold text, images, or other content — or to make a division on the page, to separate one section of content from another. Unlike other HTML tags, <div> has no inherent formatting features. Unless CSS is applied to a <div> tag, it can seem invisible on a page, yet the tag has a powerful purpose because any content surrounded by opening and closing <div> tags becomes an object (or a box) that can be formatted with CSS.

I used the box model to create all the templates in this book. As a result, to change the size or positioning of a section of a Web page in one of the templates featured in Chapters 79, you need to edit the corresponding style. When you create or edit a style that corresponds to a <div> tag ID, you can specify properties such as alignment, border, margin, height, and width to control how the <div> tag is displayed on the page. In the template chapters, you find step-by-step instructions for adding your own images and text to these templates, and for making minor changes to the styles of the page. To edit the styles that control the positioning, width, and other display options of the <div> tags that make up these pages layouts, read Chapter 6, where you find instructions for editing a CSS layout.

Each <div> in the page templates has an ID, which corresponds to a style in the style sheet. The ID appears in the HTML within the <div> tag brackets so that the browser knows which style to use to control the formatting of that <div> when it displays the page. For example, all the templates have a <div> with the ID container that controls the overall size of the design area. If you look at the code, the <div> looks like this:

<div id="container"></div>

In the corresponding style sheet, which you can easily access through the CSS Panel in Dreamweaver, you'll find a style called #container, which controls the width and other settings for that <div>. If this all seems a bit confusing, don't worry too much at this stage. When you put all this theory into practice with the templates in Chapters 79, it makes a lot more sense, and you find more detailed instructions for editing CSS layouts in Chapter 6.

To learn more about CSS, you can find many more lessons on how to create, define, and edit styles in my book Dreamweaver CS4 For Dummies (Wiley).

Understanding style selectors

One of the first things you need to understand when you create new styles is which selector to use for which job. The selector determines the kind of style you will create. Each selector option has different naming restrictions and purposes. If you're completely new to working with styles, this may not make much sense yet, but this is a fundamental part of work with styles, and I encourage you to read through all these descriptions of selectors so that you can appreciate your options before you move on.

Tip

Don't feel you have to memorize all this. Instead, consider folding down the corner on this page so you can refer to this list of selectors when you create and edit styles later.

Class selectors

The class selector is the most versatile selector option. Class styles can be used to format any element (from text to images to multimedia), and they can be used as many times as you like on any page in a Web site.

Class style names always begin with a period, and you can create class styles with any name as long as you don't use spaces or special characters. Note: Hyphens and dashes are okay. Thus, you could create a style called caption for the text that appears before your pictures.

.caption

Dreamweaver helps you with the opening period (or a dot). If you choose class as the selector type and forget to include a dot at the beginning of the name, Dreamweaver adds one for you. Note: Don't include any space between the dot and the style name, though.

One other thing that can make styles confusing is that when you apply a class style to text or another element, the dot doesn't appear in the name when it's added to your HTML code. Thus, if you applied the .caption style to a paragraph tag to format the text under an image, it would look like this:

<p class="caption">This is a photo of an Egret in flight.</p>

Note

Class styles must be applied to an element, such as the paragraph tag shown in this example. Class tags can even be added to elements that are already defined by other styles.

When you create a class style in Dreamweaver, the style is displayed in the CSS Styles panel on the right side of the workspace (shown in Figure 4.7). You can apply class styles by using the CSS drop-down list, also shown in Figure 4.7.

Styles created with class selectors are available from the CSS drop-down list and can be applied to any element and used as many times as you like on any pag.

Figure 4.7. Styles created with class selectors are available from the CSS drop-down list and can be applied to any element and used as many times as you like on any pag.

One more thing about styles for now: It's common to create styles to align images and other elements to the right or left of a page, and styles with the names .float-right and .float-left are included in all the templates included with this book. These styles commonly include margin spacing to create a little white space between an image and text when text is wrapped around the aligned image, as shown in Figure 4.7.

For more details and step-by-step instructions for creating and applying styles with class selectors, see Chapter 6.

ID selectors

Think of ID styles as the building blocks of most CSS layouts. What's special about ID styles is that they should be used only once per page. This makes them ideally suited to formatting <div> tags and other block-level elements that are used to create distinct sections in a design and only appear once per page.

ID styles must begin with a pound (#) character. Similar to class styles, Dreamweaver adds # to the beginning of the style name automatically if you forget to include it. And, like with a class style, don't include a space between # and the style name.

The ID selector option is a new addition to the CSS Rule dialog box in Dreamweaver CS4. (In CS3, you had to choose the Advanced option to create an ID style.) Similar to class styles, you can name ID styles anything you like as long as you don't use spaces or special characters (again hyphens and underscores are okay). An ID style used to identify the sidebar section of a page could look like this:

#sidebar

Similar to class styles, # isn't used in the HTML code when a style is applied to an element, such as a <div> tag like this:

<div id="sidebar">Between these tags with the sidebar ID style, you would include any headlines, text, or other elements in your sidebar.</div>

In the predesigned CSS layouts included in Dreamweaver, all the designs are created by combining a series of <div> tags with ID styles using names like #container, #header, and #footer to identify the main sections of the design. In Figure 4.8, you can see how a collection of ID and class styles are displayed in the CSS Styles panel after they're created.

Styles created with the ID selector should be used only once per page and are ideal for creating a CSS layout.

Figure 4.8. Styles created with the ID selector should be used only once per page and are ideal for creating a CSS layout.

Tag selectors

The tag selector is used to redefine existing XHTML tags. Select this option if you want to change the appearance of an existing XHTML tag, such as the <h1> (heading 1) tag or the <ul> (unordered list) tag.

In many cases, redefining existing XHTML tags with CSS has advantages over creating new styles. For example, content formatted with the heading 1 tag is well recognized on the Web as the most important text on a page. For that reason, many search engines give priority to text formatted with the heading 1 tag. Similarly, the hierarchical structure of the <h1><h6> tags helps ensure that, even if a visitor to your site changes the text size in his Web browser, text formatted with the heading 1 tag is still larger relative to text formatted with an heading 2 tag, which is larger than text formatted with the heading 3 tag, and so on.

The ability to change the appearance of headings and other tags with CSS makes it possible to retain these advantages while still being able to use the font, size, color, spacing, and other formatting options that you prefer in your Web design. When you use the tag selector, the style definition is applied automatically to any text or other element that's been formatted with the corresponding tag. Thus, if you've formatted a headline with an <h1> tag and then create a new <h1> style, the formatting you used to define the style will apply automatically to the headline as soon as the style is created.

When you choose a tag selector type, all the XHTML tags become visible in a drop-down list in the New CSS Rule dialog, making it easy to choose the tag style you want to create, such as the H1 tag shown in Figure 4.9.

You can redefine the appearance of any XHTML tag by creating a style with a tag selector.

Figure 4.9. You can redefine the appearance of any XHTML tag by creating a style with a tag selector.

Creating compound styles

The compound selector can be used to combine two or more style rules to create a style definition that displays only when one style is contained within another. Compound styles are useful when you want to do something like use the heading 1 tag multiple times to format headlines in different ways on the same Web page. For example, you could create one style for headlines that appear in the main story area of a page and then create another style for headlines that appear in the sidebar on the page and still use the heading 1 tag to format both.

Compound styles are created by combining ID, class, or tag styles and look like this:

#sidebar1 h1

See Figure 4.10 for an example of how an <h1> style defined like this within a #sidebar1 ID style looks in the New CSS Rule dialog box. Note that you must include a space between each name or tag in a compound style and that you don't include the brackets around tag in a style name. In this example, the style definition will apply only to <h1> tags that appear within another element, such as a <div> tag with an ID style #sidebar1.

Use the compound style selector to combine styles.

Figure 4.10. Use the compound style selector to combine styles.

If a compound style combines more than one tag, it's written like this:

#sidebar1 h1 a:link

Again, you must include a space between each name or tag. In this example, you see a style that defines the appearance of the active link tag only when the link is located inside an element formatted with the <h1> tag that's also inside an element formatted with the #sidebar1 ID. A compound style like this makes it possible to create links that look different when they appear in a headline in the sidebar of a page than when they appear in another part of the sidebar.

After you figure out the differences among these style selector options and when they're best used, you're well on your way to mastering the art of creating Web pages with CSS in Dreamweaver. (Find more information about compound styles in Chapter 6.)

Understanding rule definition options

In CSS, you have the option of creating internal, external, or inline styles. You can even use a combination of these options, or attach multiple external style sheets, to the same Web page. Here's an explanation of these options:

  • Internal styles: If you create internal styles, the CSS code is stored in the <head> area at the top of the HTML page you're working on, and the styles can be applied only to the page in which they were created. If you're just creating a one-page Web site or you're creating styles that will be used only on one page, an internal style sheet is fine, but for most sites, external style sheets offer many advantages.

  • External styles: If you save your styles in an external style sheet, they're stored in a separate file with a .css extension. External style sheets can be attached to any or all the pages in a Web site in much the same way that you can insert the same image into multiple pages. You can also attach multiple external style sheets to the same page. For example, you can create one style sheet for styles that format text and another for layout styles. You can also create external style sheets for different purposes, such as one for print and one for screen display. One of the biggest advantages of external style sheets is that they make it faster and easier to create new pages, and they make it possible to update styles across many pages at once.

  • Inline styles: Inline styles are created within a document at the place that a style is used and only apply to the element they're attached to in the document. These are generally considered the least useful of the three style sheet options because any changes to the defined style must be made to the code that contains the element, which means you lose many of the benefits of styles, such as the ability to make global updates and create very clean, fast-loading code. For example, creating one style for all your headlines and saving it in an external style sheet is more efficient than applying the style formatting options to each headline separately.

At the bottom of the New CSS Rule dialog box, shown in Figure 4.11, you find a Rule Definition drop-down list. Use this list to specify where and how you want to save each new style that you define. The options are

  • This Document Only: Create an internal style that can only be used in the open document.

  • New Style Sheet file: Create the new style in an external style sheet and create a new external style sheet simultaneously.

  • An existing external style sheet: Choose any existing external style sheet attached to the page by selecting the name of the style sheet from the Rule Definition drop-down list. In Figure 4.11, I am selecting an existing style sheet with the name main.css.

Tip

If you're creating a style that you'll likely want to use on more than one page in your site, saving the style to a new or existing external style sheet is your best choice. If you save a style in an internal style sheet and later decide you want to add it to an external style sheet, you can move the style by clicking and dragging the style into the external style sheet list in the CSS Styles panel.

When defining a new CSS rule, save it in an internal or external style sheet.

Figure 4.11. When defining a new CSS rule, save it in an internal or external style sheet.

Looking at the code behind the scenes

Even if you prefer not to look at the code behind your Web pages, it's helpful to at least have some familiarity with different kinds of tags, CSS, and other code that Dreamweaver creates for you when you design Web pages. The following examples show what the CSS code in an internal or external style sheet would look like in Dreamweaver for the following styles:

  • An ID style created with the ID selector, that is named #container, and is defined as 780 pixels wide with the left and right margins set to auto (a cool trick for centering a CSS design, covered in Chapter 6).

  • A style created with a class selector, that is named .caption, and is defined as Verdana, Arial, Helvetica, sans serif, small, italic, and bold.

  • A style created with a tag selector to redefine the HTML tag <h1> — as Arial, Helvetica, sans serif, large, and bold. (Note: Because the heading tags already include bold formatting, it's not necessary to include bold in the style definition.)

#container {
          width: 780px;
          margin-right: auto;
          margin-left: auto;
}
.caption {
          font-family:  Verdana, Arial, Helvetica, sans-serif;
          font-size: small;
          font-style: italic;
          font-weight: bold;
}
H1 {
          font-family: Arial, Helvetica, sans-serif;
          font-size: large;
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset