Professional Documents
Culture Documents
Outline
In this Lecture, we begin our discussion of CSS
Cascading Style Sheets
Here, we focus on constructing Individual Style Rules
Specifically, we survey the Construction of Selectors,
which allows pin-point application of formatting.
As we shall see, we may target an Element for formatting
based on:
Element type or name
Element’s class or id
Simple or complex information about the Element’s context
The presence of attributes and values
Etc…
This will prepare us for related discussions of:
Methods of style application (e.g., style sheets)
Actual formatting patterns (declarations)
Introduction
After establishing the basic structure of your page…
You will want to apply formatting rules.
This is accomplished separately, via Style Rules.
Soon, we will discuss application methods:
Applied separately, as Inline style rules.
Applied in groups, via style sheets:
Embedded (Internal) style sheets;
External style sheets.
Here, the selector is just the name of the desired type of element…
The specified format is then applied to all such elements.
So, here we set the color property (of all h1 elements) to red.
Notes:
Not all selectors specify an element’s name…
The name will be omitted when dealing with classes;
The wild-card selector (*) also matches any element name (more shortly…).
You may also string these selectors together, using commas:
Selecting Elements by Class or ID
You may select elements by class or id…
If you have already labeled the elements appropriately…
Using the class or id attribute, as we saw earlier (Lecture 6).
To select elements based on membership in a class:
Specify the element type followed by period, and the class name:
To select ALL elements of the class, just omit the element name
Example: .news{color : red}
To select an element based on its id:
Specify the element type followed by #, and the id:
Example: Basic Element Selection
Selecting by Context: Descendants
You may also select elements via context (relative location)
Based on an element’s ancestor, parent, or sibling.
Let’s take the first term…
The ancestor of an element, y:
Is defined as any element, x that contains element y;
This just means y is nested within x (at some depth).
Element y is then called a descendant of element x.