Home / Articles / CSS Basics

CSS Basics

Chapter Description

Familiarize yourself with CSS and learn CSS (cascading style sheets) terms and terminology, the difference between HTML and CSS formatting, different methods for writing CSS rules and markup, how the cascade, inheritance, descendant, and specificity theories affect the way browsers apply CSS formatting, and new features and capabilities of CSS3.

HTML vs. CSS formatting

When comparing HTML-based formatting to CSS-based formatting, it’s easy to see how CSS produces vast efficiencies in time and effort. In the following exercise, you’ll explore the power and efficacy of CSS by editing two webpages, one formatted by HTML and the other by CSS.

  1. Launch Dreamweaver (2020 release) or later, if it’s not currently running.

  2. Create a new site based on the lesson04 folder, using the instructions in the “Getting Started” section at the beginning of the book. Name the site lesson04.

  3. Choose File > Open.

  4. Navigate to the lesson04 folder, and open html-formatting.html.

  5. Click the Split view button. If necessary, choose View > Split > Split Vertically to split Code and Live view windows vertically, side by side.

    Note how each element of the content is formatted individually using the deprecated <font> tag and the attribute color="blue" in each <h1> and <p> element.

  6. Replace the word "blue" with "green" in each <h1> element in which it appears. If necessary, click the mouse cursor in the Live view window to update the display.

    The <h1> elements display in green now in each line where you changed the color value. As you can see, formatting using the obsolete <font> tag is not only slow but also prone to error. Make a mistake, like typing greeen or geen, and the browser will ignore the color formatting entirely.

  7. Open css-formatting.html from the lesson04 folder.

  8. If it’s not currently selected, click the Split view button.

    The content of the file is identical to the previous document, except that it’s formatted using CSS. The code that formats the HTML elements appears in the <head> section of this file. Note that the code contains only two color:blue; attributes.

  9. In the property for the h1 rule color: blue; select the value blue and type green to replace it. If necessary, click in the Live view window to update the display.

    In Live view, all the heading elements display in green. The paragraph elements remain blue.

  10. Select the value in the p rule color: blue; and type green to replace it. Click in the Live view window to update the display, if necessary.

    In Live view, all the paragraph elements have changed to green.

  11. Close all files and do not save the changes.

In this exercise, CSS accomplished the color change with two simple edits, whereas using the HTML <font> tag required you to edit every line individually. Now think how tedious it would be to go through thousands of lines of code and hundreds of pages on a site to make such a change. Is it any wonder that the W3C, the web standards organization that establishes internet specifications and protocols, deprecated the <font> tag and developed cascading style sheets? This exercise highlights just a small sample of the formatting power and productivity enhancements offered by CSS, unmatched by HTML alone.

3. HTML defaults | Next Section Previous Section

There are currently no related articles. Please check back later.