Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Login

Register Now

Welcome to All Test Answers

Chapter 4- Cascading Style Sheets

Download  file with answers

Not a member!

Create a FREE account here to get access and download this file with answers


Chapter 4: Cascading Style Sheets

 

TRUE/FALSE

 

  1. Style rules express the style characteristics for an HTML element.

 

  1. You can combine selectors and property declarations in a variety of ways.

 

  1. It is not necessary to use the <style> element in an external style sheet.

 

  1. The advantage of the external style sheet is that you can state the style rules in one document and affect all the pages on a Web site.

 

  1. You will probably use the style attribute method of styling an element the most.

 

 

  1. CSS allows comments within the <style> element, but not in an external style sheet.

 

  1. By default, most CSS properties inherit from parent elements to child elements.

 

  1. The difference between an id attribute and a class attribute is that an id should refer to only one occurrence within a document.

 

  1. Rules with more specific selectors take precedence over rules with less specific selectors.

 

  1. The !important keyword allows you to specify that a rule should take precedence no matter what the order in the style sheet.

 

MULTIPLE CHOICE

 

  1. A style rule is composed of ____ parts.
a. two c. four
b. three d. five

 

 

  1. In a style rule, the ____ determines the element to which a rule is applied.
a. style tag c. declaration
b. selector d. style sheet

 

 

  1. In a style rule, the ____ details the exact property values.
a. selector c. style tag
b. style sheet d. declaration

 

 

  1. A declaration is enclosed by ____.
a. () c. []
b. <>  d. {}

 

 

  1. In a style rule, the ____ is a quality or characteristic, such as color, font size, or margin.
a. value c. declaration
b. selector d. property

 

 

  1. In a style rule, a property is followed by a ____.
a. semicolon (;) c. comma (,)
b. colon (:) d. question mark (?)

 

 

  1. In a style rule, a value is followed by a ____.
a. colon (:) c. semicolon (;)
b. question mark (?) d. period (.)

 

  1. ____ is simply a text document that contains the style rules.
a. An internal style sheet c. The style attribute
b. The <style> element d. An external style sheet

 

 

  1. External style sheets have a(n) ____ extension.
a. .ess c. .cs
b. .ss d. .css

 

 

  1. The ____ element lets you establish document relationships.
a. <style> c. <relate>
b. <link> d. <head>

 

 

  1. Style rules contained in ____ affect only the document in which they reside.
a. an internal style sheet c. the <body> tag
b. an inline style d. an external style sheet

 

 

  1. CSS comments begin with ____.
a. /? c. /*
b. */ d. ?/

 

 

  1. The elements in an HTML document are structured in a hierarchy of ____ elements.
a. unrelated c. sibling
b. parent and child d. related

 

 

  1. ____ elements contain nested elements called ____ elements.
a. Child, parent c. Sibling, child
b. Parent, sibling d. Parent, child

 

 

  1. The simplest type of selector is the ____ selector.
a. grouping c. type
b. combining d. descendant

 

 

  1. When grouping selectors, the selectors are separated by ____.
a. semicolons c. periods
b. colons d. commas

 

 

  1. When combining declarations, the declarations are separated by ____.
a. semicolons c. periods
b. colons d. commas

 

 

  1. The symbol for the universal selector is the ____.
a. asterisk ( * ) c. period ( . )
b. comma ( , ) d. apostrophe ( ‘ )

 

 

  1. The ____ selector lets you write rules, give them a name, and then apply that name to any elements you choose.
a. div c. core
b. class d. span

 

 

  1. In a style rule,the ____ flag character indicates that the selector is a class selector.
a. question mark (?) c. semicolon (;)
b. period (.) d. colon (:)

 

 

  1. The ____ element can be used with the class and id attributes to create logical divisions on a Web page.
a. <span> c. <class>
b. <div> d. <paragraph>

 

 

  1. The ____ element lets you specify inline elements within a document that have their own name and style properties.
a. <span> c. <class>
b. <div> d. <paragraph>

 

 

  1. Pseudo-____ select elements based on characteristics other than their element name, such as changing the color of a new or visited hyperlink text.
a. elements c. classes
b. attributes d. ids

 

 

  1. The fact that style sheets ____ means that multiple style sheets and style rules can apply to the same document.
a. join c. cascade
b. stack d. coincide

 

 

  1. The ____ states selectors let you choose an element based on its state of user interaction.
a. hover c. W3C attributes
b. pointer d. UI element

 

 

COMPLETION

 

  1. ____________________ let you control the display characteristics of your Web site.

 

ANS: 

Cascading Style Sheets (CSS)

CSS (Cascading Style Sheets)

Cascading Style Sheets

CSS

 

PTS:   1                    REF:   151

 

  1. A set of style rules is called a(n) ____________________.

 

ANS:  style sheet

 

PTS:   1                    REF:   152

 

  1. In a style rule, a declaration contains a(n) ____________________ and a value.

 

ANS:  property

 

PTS:   1                    REF:   153

 

  1. In a style rule, the ____________________ is the precise specification of the property.

 

ANS:  value

 

PTS:   1                    REF:   153

 

  1. Placing style sheets in a(n) ____________________ document lets you specify rules for multiple Web pages.

 

ANS:  external

 

PTS:   1                    REF:   155

 

  1. The ____________________ is useful for testing styles during development.

 

ANS:  style attribute

 

PTS:   1                    REF:   156

 

  1. You can style multiple document elements with just a few style rules if you let ____________________ work for you.

 

ANS:  inheritance

 

PTS:   1                    REF:   160

 

  1. The ____________________ element is a block-level element, and <span> is its inline equivalent.

 

ANS: 

<div>

div

 

PTS:   1                    REF:   170

 

  1. The CSS cascading mechanism determines which rules are applied to document elements by assigning a(n) ____________________ to each rule.

 

ANS:  weight

 

PTS:   1                    REF:   180

 

  1. CSS applies weight to a rule based on its ____________________ within a style sheet.

 

ANS:  order

 

PTS:   1                    REF:   181

 

ESSAY

 

  1. Briefly describe the concept of style sheets. What are selectors, declarations, properties and values?

 

ANS: 

In CSS, style rules express the style characteristics for an HTML element. A set of style rules is called a style sheet. Style rules are easy to write and interpret.

 

A style rule is composed of two parts: a selector and a declaration. The style rule expresses the style information for an element. The selector determines the element to which the rule is applied. Selection is the key to working with CSS. The declaration, contained within curly brackets, details the exact property values.

 

The property is a quality or characteristic, such as color, font size, or margin, followed by a colon (:). The value is the precise specification of the property, such as blue for color, 125% for font size, or 30 px (pixels) for margin, followed by a semicolon (;). CSS contains a wide variety of properties, each with a specific list of values.

 

PTS:   1                    REF:   152-153

 

  1. What are the three ways that you can combine CSS style rules with HTML code? Describe each method, along with an example of using the method.

 

ANS: 

Inline style: You can define the style for a single element using the style attribute.

 

<h1 style=“color: blue”>Some Text</h1>

 

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. You will probably use this method of styling an element the least, because it affects only one instance of an element in a document.

 

 

Internal style sheet: Use the <style> element to created an internal style sheet in the <head> section of the document. Style rules contained in an internal style sheet only affect the document in which they reside. The following code shows a <style> element that contains a single style rule:

 

<head>

<title>Sample Document</title>

<style type=“text/css”>

h1 {color: red;}

</style>

</head>

 

In this code sample, note the type attribute to the <style> element. The value “text/css” defines the style language as Cascading Style Sheets.

 

External style sheet: Placing style sheets in an external document lets you specify rules for multiple Web pages. This is an easy and powerful way to use style sheets because it lets you control the styles for an entire Web site with one style sheet file. Additionally, external style sheets are stored in the user’s cache, so once downloaded, they are referenced locally for every file on your Web site, saving time for your user.

 

An external style sheet is simply a text document that contains style rules. External style sheets have a .css extension.

 

The <link> element lets you establish document relationships. It can be used only within the <head> section of a document. To link to an external style sheet, add the <link> element as shown in the following code:

 

<head>

<title>Sample Document</title>

<link href=“styles.css” rel=“stylesheet” type=“text/css”>

</head>

 

The <link> element in this code tells the browser to find the specified style sheet. The href attribute states the relative URL of the style sheet. The rel attribute specifies the relationship between the linked and current documents. The browser displays the Web page based on the CSS display information.

 

The advantage of the external style sheet is that you can state the style rules in one document and affect all the pages on a Web site. When you want to update a style, you only have to change the style rule once in the external style sheet.

 

PTS:   1                    REF:   153-156

 

  1. What are the four basic selection techniques? Briefly describe each technique.

 

ANS: 

Using Type Selectors: A type selector is used to apply a rule to every instance of the element in the document. This is the simplest kind of selector, and many style sheets are composed primarily of type selector style rules.

 

For instance in the following code:

 

h1 {color: red;}

 

Grouping Selectors: To make your style rules more concise, you can group selectors to which the same rules apply. For example, the following style rules set the same declaration for two different elements—they set the color of <h1> and <h2> elements to red:

 

h1 {color: red;}

h2 {color: red;}

 

These two style rules can be expressed in a simpler way by separating the selectors with commas:

 

h1, h2 {color: red;}

 

Combining Declarations: In many instances you want to state multiple property declarations for the same selector. The following style rules set the <p> element to 12-point blue text:

 

p {color: blue;}

p {font-size: 125%;}

 

These two style rules can be expressed in a simpler fashion by combining the declarations

in one rule. The declarations are separated by semicolons:

 

p {color: blue; font-size: 125%;}

 

Using Descendant Selectors: A descendant selector (sometimes known as a contextual selector) is based on the hierarchical structure of the elements in the document tree. This selector lets you select elements that are the descendants of other elements. For example, the following rule selects only <em> elements that are contained within <p> elements. All other <em> elements in the document are not affected.

 

p em {color: blue;}

 

Notice that the selector contains multiple elements, separated only by white space. You can use more than two elements if you prefer to choose more specific selection characteristics. For example, the following rule selects <em> elements within <li> elements within <ul> elements only:

 

ul li em {color: blue;}

 

PTS:   1                    REF:   161-163

 

  1. Explain pseudo-elements.

 

ANS: 

Pseudo-elements let you change other aspects of a document that are not classified by elements, such as applying style rules to the first letter or first line of a paragraph. For example, you might want to create a drop initial or drop capital that extends below the line of type, or make the first line of a paragraph all uppercase text. These are common publishing design techniques that are not possible with standard HTML code. With CSS you can use the :first-letter and :first-line pseudo-elements to add these two style characteristics to your documents.

 

PTS:   1                    REF:   173

 

  1. Define “cascade” as it relates to CSS and explain the CSS cascading mechanism.

 

ANS: 

One of the fundamental features of CSS is that style sheets cascade. This means that multiple style sheets and style rules can apply to the same document. HTML authors can attach a preferred style sheet, while the reader might have a personal style sheet to adjust for preferences such as human or technological handicaps. However, only one rule can apply to an element. The CSS cascading mechanism determines which rules are applied to document elements by assigning a weight to each rule based on the following three variables:

 

Specificity of the selector

Order of the rule in the style sheet

Use of the !important keyword

 

PTS:   1                    REF:   180

About

Leave a reply

Captcha Click on image to update the captcha .

error: Content is protected !!