Chapter 6 - Introducing Cascading Style Sheets

REPUBLIC OF NICARAGUA

 

Up

Chapter 6 Review Questions

1.   What are the two parts of a style rule?

A style rule is composed of two parts: a selector and a declaration.

2.   What are the three ways to combine CSS rules with your XHTML code?

You can combine CSS rules with XHTML code in the following three ways:

n      The style attribute

n      The <style> element

n      An external style sheet

3.   List two reasons to state a style using the style attribute.

You generally use the style attribute to override a style that was set at a higher level in the document, as when you want a particular heading to be a different color from the rest of the headings on the page. The style attribute is also useful for testing styles during development.

4.   What are the advantages of using an external style sheet?

Placing style sheets in an external document lets you specify rules for multiple Web pages.

5.   What is the inheritance default for CSS rules?

By default, CSS rules inherit from parent elements to child elements.

6.   What is the benefit of the !important declaration?

The !important declaration lets users override the author’s style rules.

7.   Write a basic style rule that selects <h1> elements and sets the color property to red.

h1 {color: red;}

8.   Add the <p> element as an additional selector to the rule you created for question 7.

h1 {color: red;}

p {font-family: sans-serif;}

9.   Add a font-size property to the rule and set the size to 14 points.

h1 {color: red;}

p {font-size: 14pt;}

10. Write a style rule that selects <ul> elements only when they appear within <p> elements and set the color property to red.

p ul {color: red;}

11. Write the style rule for a class selector named note. Set the font-weight property to bold.

.note { font-weight: bold;}

12. Restrict the rule you developed for question 11 so it can be used only with <p> elements.

.note { font-weight: bold;}

<p class="note">text</p>

13. What is the difference between <div> and <span>?

The difference between <div> and <span> is their element display type. <div> is a block-level element, and <span> is its inline equivalent.

14. Write a style rule that sets the default document text color to red.

body {color: red;}

15. What is the advantage of working with the class attribute?

The class attribute lets you write rules, give them a name, and then apply that name to any elements you choose.

16. What element does this selector choose? 

      p ul li

Selects <li> elements within <ul> elements within <p> elements only

17. What element does this selector choose? 

      div p *

all <p> elements

What element does this selector choose?

      p.warning

a class named warning

18. What is the advantage of working with the id attribute?

Because id refers to only one instance of the id attribute value within a document, this allows you to specify an id value and apply it to one unique element in a document.

19. Write a style rule that applies a yellow background color to <a> elements when the user points the mouse to a hypertext link.

a:link {color: yellow;}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

R. Stewart Braswell, Webmaster
Last Updated: 20 April 2012