The Computer Gal Logo - Laptop with coffee and plants
Understanding the Scope and Precedence of Styles
The Computer Gal on Facebook
Watch this page for ongoing web development tips

This exercise is a series of questions. The answers require experimentation

If the body tag is rewritten in an external style sheet, can the style be overridden internally?

  1. Create a new CSS file named BodyTagTest.
  2. Add a comment at the top of the file that notes that this file contains a body style for testing purposes only.
  3. Define the body tag with a font size and a color.
  4. Create a new HTML file, save the file as TestFiles/Precedence1.html, and attach the new style sheet.
  5. Type some words in the file. The font should be formatted the way you set the style.
  6. Now rewrite (dffierent size and color) the body tag in the <head> of the file.
  7. Did the font formatting change? Which has precedence, externally rewriting the body or internally rewriting the body? Where should you look first to see what is controlling the formatting?
  8. Sample

If the body tag is rewritten externally, can the style be overridden with an internal style?

  1. Add a new class style to your BodyTagTest file that has different font formatting.
  2. Create a new HTML file, save the file as TestFiles/Precedence2.html, and attach the new style sheet.
  3. Type some words in the file. The font should be formatted the way you set the style.
  4. Now rewrite (dffierent size and color) the body tag in the <head> of the file.
  5. Did the font formatting change? Which has precedence, externally rewriting the body or internally rewriting the body?

What happens if someone decides to format text in the <body> with the other styles in existence?

  1. Save the TestFiles/Precedence2.html file as TestFiles/Precedence3.html, and attach the new style sheet.
  2. Add inline text formatting to the <body>, using the same properties as the previous styles.
  3. Did this override the previously defined styles?
  4. How can all these scenarios lead to sloppy code? What might be one way that these levels could be used appropriately?

 

Nora McDougall | Missoula, Montana 59801 | 406.253.4045 | Contact Nora
© 2011, Nora McDougall-Collins