Computer Eng. Technology - Comp. Science

CST8238_350 Web Programming

(i) What are the main benefits of using CSS?

  • Easier to maintain and update
  • Greater consistency in design
  • More formatting options
  • Lightweight code
  • Faster download times
  • Search engine optimization benefits
  • Ease of presenting different styles to different viewers
  • Greater accessibility

(ii) What are different parts of a CSS style rule?

A CSS rule is made up of a selector and a declaration
<selector> . <className> { <Property> : <value>}

Example:
h1.headerFont12 {
font-size: 12px;
}

(iii) What are an element selector and grouped element selector in CSS? Provide an example of each.

The element selector selects all elements with the specified element name.

p {
padding: 15px;
}

We can group selectors using a comma (,) separator.

td, th {
padding: 15px;
}

(iv) What are class selectors in CSS? What are id selectors in CSS?

The .class selector selects elements with a specific class attribute.
The #id selector styles the element with the specified id.

(v) What are contextual selectors in CSS?

"Contextual selectors" in CSS allow you to specify different styles for different parts of your
document. You can assign styles directly to specific HTML tags, or you can create independent
classes and assign them to tags in the HTML. Either approach lets you mix and match styles.

(vi) What are the three cascade principles used by browsers when style rules conflict?

When conflict occurs, the declaration with the most weight is used. The Cascade principles are:
Inheritance, specificity and location