Collected by Elizabeth Janson Home Page |
|
The selector is the link between the HTML document and the style sheet.
Style sheet selectors are the code that preceeds the bracketed definitions.
This introduction avoids selectors which have names that are not HTML elements.
We are talking about the way the rule is identified in the Style Sheet and then in the HTML listing.
Block elementsBlock elements do have line breaks. They may occur in other block elements, and may contain both block and inline elements, but cannot occur in inline elements.I am taking my lists from HTML4. Go here for more on depreciating elements or here to review familiar elements.
Inline elementsInline elements do not have line breaks (are ended by the line break). Can occur in block elements or other inline elements, cannot contain block elements.I am taking my lists from HTML4
SelectorA selector is a string that identifies what elements the corresponding rule applies to. A selector can either be a simple selector (e.g. 'H1'), a contextual selector (e.g. 'H1 B') which consists of several simple selectors divided by white space, or a grouped selector (eg 'H1, H2) where the simple selectors are divided by commas.Simple selectorA selector that matches elements based on the element type and/or attributes, and not the element's position in the document structure, is a simple selector.Contextual selectorsContextual selectors consist of several simple selectors separated by whitespace. Contextual selectors omit the comma separator and are a lot like conditional statements - the style declarations that follow them are invoked only when certain conditions are met. For example, suppose you'd like all bold italic text in your document to appear in blue Arial.B { color: blue }In the example above, the search pattern matches if 'I' is a descendant of 'B', i.e. if 'I' is inside an 'B' element. Your contextual selector could look like this: <HEAD>I am Bold, I am Italic, Go on, try it yourself. Do I look like I'm lying? Grouping
To reduce the size of style sheets, one can group selectors in comma-separated lists: H1 B { color: red }Warning : the equivalence is true in this example because all selectors are valid selectors. If one (or more) of these selectors is invalid, the group made of the four selectors is itself invalid, invalidating the rule; then the equivalence is false. You may want the same element (eg H1) to have different styles at different places in a page. <H1 STYLE= {background-color:pink}> With the above, the heading</H1> now has a pink background.</P> With the above, the headingnow has a pink background.Check if this change will carry forward, by using <H1>Inheritance</H1> InheritanceAnswer is NO, because the closing tag </H1> ended the style of the H1 element.It is VERY important that all container tags be CLOSED. |
CSS begins here |
Back to introduction, or on to Id selectors. |
This page is part of Elizabeth Janson's web site
http://www.oocities.org/elizatk/index.html
Tetbury residents in the Eighteenth Century my Australian Family History and Barrie, our Family Poet. |