![]() | |||||||
| |||||||
HomeWeb DevelopmentShort ContentsIntroductionCSS Basics Selectors Terminology Media Types Paged Media Aural Media Colours Fonts Text Blocks Lists & counters Tables Miscellaneous Full ContentsIntroductionChanges from CSS1Other CSS sites Download this Guide CSS BasicsSetting StylesUsing external files ...media dependant Setting Style values Comments Inheritance Selectors...by class...by id ...contextual ...all elements ...if a child ...adjacent elements ...by attributes Psuedo Classes ...<A> links :hover :active :focus :lang :firstchild Psuedo Elements ...first line ...first letter ...:before and :after ...inserting content TerminologyCascades"! important" CSS element model Block elements Guide Terminology Units ...lengths ...colours Media Types...giving style...supported types Paged Mediamarginspage size crop marks left, right, first pages page break before page break after page break inside page names orphaned content widowed content Aural Mediavolumespeak pausebefore pauseafter pause cuebefore cueafter cue playduring azimuth elevation speech rate voice family average pitch pitch range stress richness punctuation numbers table headers ColoursForeground colourBackground ...-color ...-image ...-repeat ...-attachment ...-position FontsFont...-family ...-style ...-variant ...-weight ...-size ...-sizeadjust ...-stretch Textword-spacingletter-spacing text-decoration text-shadow vertical-align text-transform text-align text-indent line-height quotes Blocksindividual marginsall margins individual padding all padding border widths all border-widths border-color border-style individual borders all borders width min width max width height min height max height float clear position ...where layered position text direction bidirectional override line height vertical align overflow clipping visibility Lists & counterslist-stylelist-style-type list-style-image list-style-position marker offset resetting counters incrementing counters nesting counters counter appearance displaying counters Tablescaption positionlayout method border display border spacing empty cells MiscellaneousDisplayRun-in boxes whitespace cursors outline outline width outline style outline colour |
SelectorsRecall that these are the HTML elements to which style information is applied. However, you can be more specific...Selecting by ClassBy assigning elements "classes", you can use these class names to specify style:<STYLE TYPE="text/css"> H1.classname { ..... } .class2 {style information for all elements with class=class2} </STYLE> ..... <H1 CLASS=classname>This text will be affected by the above SYTLE info.</H1> <H2 CLASS=class2>So is this text</H1> Selecting by IDIt is possible to use the id attribute in HTML tags to specify style information. The element is identified by placingID= in the opening tag. The style information is then specified by using the form
elementname#
Example: <STYLE> #id1 { color:green} (make the color green for all text in any element with ID=id1) H1#id2 { color:blue} (all H1 elements with ID=id2 are displayed in blue) </STYLE> ..... <P ID=id1>green text</P> <H2 ID=id2>blue text</h2> ContextualYou can specify that style is only applied to elements which have certain "parents" (elements which they are contained within).e.g. H1 EM { styleinfo }; /*all EM text within a H1 tag */ UL UL LI { styleinfo }; /*all LI items within two UL sets */ .classname H1 { styleinfo };/* all H1 within elements with CLASS=classname*/ #IDname H1 { styleinfo }; /* all H1 text within elements with ID=IDname*/ DIV.IDname H1 { styleinfo };/* all H1 text within DIV tags with ID=IDname*/ Selecting All elementsThis can either be done by assigning properties to the BODY object, or by use of the universal selector:
Child SelectionAn element is a child of another if it is contained within that other element. For example, in<h1> <h3> </h3> </h1> , H3 is a child of H1, but anything within the H3 tags is a child of H3 and not H1. If we wanted to make all H3s, which are children of H1, to be red, we would useH1 > H3 { color : red } Adjacent ElementsTo specify style for a H3 elements that immediately follows a H1 element, useH1 + H3 { color : red } .This would affect <H1>...</H1> <H3>this text</H3>
Selecting by attributesYou can add style to elements which have values specified to certain attributes. The general form is
,where relationship is one of
H1[id="the top heading"] {color : red} H1[id~=top] {color : red}The above would both have the same effect on <H1 id="the top heading"> Pseudo ClassesAnchor pseudo-classesStyle can be applied to the three types of anchor links (normal, visited, active), as indicated in the following examples...A:link { :Hover Pseudo ClassThis sets style to an element when a pointing device, usch as the mouse, is held over it. Note that it can be over-ridden if style for pseudo classes such as :link are defined after :hover.Example : a:hover {color: rgb(100%,0%,100%) }
:Active Pseudo ClassThis is used when an element becomes active, such as the time between pressing a button, and releasing it.Example : a:active {color: rgb(100%,0%,100%) }
:Focus Pseudo ClassAn element has the focus when it has been selected by a mouse click, keyboard hotkey, or by default. When in focus, it reacts to keyboard and other events, such as typing in an input box.textinput:focus {color: rgb(100%,100%,100%) }
The Language Pseudo ClassExample : h1:lang(en) {color:blue} This defines style for elements which have their language defined by the lang= HTML attribute. The above example is for english, see the settings boxes in your web browser for the codes of other languages. The above example would affect <H1 lang=en>this text</H1> First Child Pseudo ClassAn element is a child of another element if it is contained within that element. It is also the first child if it is the first element within that element. For example, in<H1> <H2></H2> <H3></H3></H1> , H2 is the first child of H1, but H3 is the second child. In this example, to select H2, we would use H1 > H2:firstchild { or H2:firstchild {
Pseudo ElementsThe first-line pseudo-element
P:first-line {
The 'first-line' pseudo-element can only be used with block-level elements, and can only be given the
following property types : font, color, background properties, word-spacing , letter-spacing , text-decoration , vertical-align, text-transform , line-height, clear . The first-letter pseudo-element'first-letter' pseudo-elements can have the following properties: font, color, background, 'text-decoration' , 'vertical-align (if 'float' is 'none'), 'text-transform' , 'line-height' , margins, padding, border, 'float' , 'clear' To make a dropcap letter span two lines:P { font-size: 12pt; line-height: 12pt } P:first-letter { font-size: 200%; float: left }The display program (a web browser) defines what characters are inside the 'first-letter' element. Normally, quotes that precede the first letter should be included. Otherwise, the first-letter information is usually ignored if the block starts with a non-letter character. Properties set on 'first-line' will be inherited by 'first-letter', but are overridden if the same property is set on 'first-letter'. Adding content :before and :afterThese simply add text before or after the contents of the specified element.p:before {content : "The start of a paragraph"} p:after {content : "The end of a paragraph"} content
This property creates content in the :before and :after sections of an element. string is text, an address is usually an internet URL, counter is described below and elsewhere in this guide, quotes are replaced by the appropriate symbol, and no-quote s act as if the quote had been closed, but doesn't actually display anything. attr( ) gives the value of the specified attribute.Counters are displayed with the content property of the :before and :after pseudo-elements.
(C)opyright, Geoff Knagge.
Continued use of this site indicates your agreement to the Conditions of use and Privacy Policy. |