Cascading Style Sheet FAQ Page
Listed below are some of the most commonly asked questions pertaining to CSS.<HEAD> <LINK REL=STYLESHEET HREF="style.css" TYPE="text/css"> </HEAD>
<HEAD>
<STYLE TYPE="text/css">
<!--
P {text-indent: 10pt}
-->
</STYLE>
</HEAD>
<P STYLE="text-indent: 10pt">Indented paragraph</P>
<LINK REL=STYLESHEET HREF="main.css" TYPE="text/css"> <STYLE TYPE="text=css"> <!-- @import url(http://www.and.so.on.partial1.css); @import url(http://www.and.so.on.partial2.css); .... other statements --> </STYLE>
<LINK REL=Stylesheet HREF="style.css" TYPE="text/css">
<LINK REL=Stylesheet HREF="style2.css" TYPE="text/css" TITLE="appropriate style description">
<LINK REL="Alternate Stylesheet" HREF="style3.css" TYPE="text/css" TITLE="appropriate style description" MEDIA=screen> <LINK REL="Alternate Stylesheet" HREF="style4.css" TYPE="text/css" TITLE="appropriate style description" MEDIA=print>NOTE: Alternate stylesheets are not yet supported.
<LINK REL=Stylesheet HREF="default.css" TITLE="combined"> <LINK REL=Stylesheet HREF="fonts.css" TITLE="combined"> <LINK REL=Stylesheet HREF="tables.css" TITLE="combined">
P {text-indent: 10pt} - CSS rule (ruleset)
{text-indent: 10pt} - CSS declaration
text-indent - CSS property
10pt - CSS value
.footnote {font: 70%} /* class as selector */
Example:And so is this
#abc123 {color: lime; background: black}
This and only this element can be identified as abc123
TD P CODE {color: red}
The element CODE will be displayed in red but only if it occurs in the context of the element P which must occur in the context of the element TD.
TD P CODE, H1 EM {color: red}
The element CODE will be displayed in red as described above AND the element EM will also be red but only if it occurs in the context of H1
P .footnote {color: red}
Any element with CLASS footnote will be red but only if it occurs in the context of P
P .footnote [lang]{color: red}
Any element with attribute LANG will be red but only if it is classed as "footnote" and occurs in the context of P
BODY ~ P {background: red; color: white}
In the above example, the P element will be declared the specified style only if it directly descends from the BODY element:
BODY ~ P ~ EM {background: red; color: white}
In the above example, the EM element will be declared the specified style only if it directly descends from the P element which in its turn directly descends from the BODY element:
BODY {background: white ! important; color: black}
In the example above, the background property will increase weight while the color property stays normal.
H1 {font-weight: bold;
font-style: italic;
font-variant: small-caps;
font-size: 160%;
font-family: serif}
With shorthand -
H1 {font: bold italic small-caps 160% serif}
To make things even simpler, the line-height property can be specified together with the font-size property, as in the below example:
H1 {font: bold italic small-caps 160%/170% serif}
H1 {font: bold 180%}
In the example above, the H1 selector is declared the FONT property which in its turn is declared the values BOLD and 180%.
H1 {font-family: font1, font2}
<P style="background: red">Hello <strong>World</strong></P>Example:
Hello World
Content of the element P will also have a red background.
Selector {declaration1; declaration2}
P {background: white; color: black}
P.name1 {color: red} /* one class of P selector */
P.name2 {color: blue} /* another class of P selector */
.name3 {color: green} /* can be attached to any element */
Example:This paragraph will be red
This paragraph will be blue
This paragraph will be green
P.name1.name2.name3 {declaration}
This paragraph has three classes attached
LI {font-style: italic}
P.first {font-style: italic}
.footnote {font-style: italic}
To reduce the size of style sheets, they can all be grouped in one list, as shown below:
LI, P.first, .footnote {font-style: italic}
H2 {font-style: italic}
H2 {color: red}
and can also be grouped into one list:
H2 {font-style: italic; color: red}
P:first-line H1:first-letterand can be combined with normal classes, like below:
P.initial:first-lineFirst-line pseudo-element allows sub-parting the element's first line and attaching specific style exclusively to this sub-part:
P.initial:first-line {text-transform: uppercase}
Example:The first line of this paragraph will be displayed in uppercase letters
First-letter pseudo-element allows sub-parting the element's first letter and attaching specific style exclusively to this sub-part:
P.initial:first-letter { font-size: 200%; color: red}
The first letter of this paragraph will be displayed in red and twice as large as the remaining letters
A:link {background: black; color: white}
A:active {background: black; color: red}
A:visited {background: transparent; color: black}
A.foot:link {background: black; color: white}
A.foot:active {background; black: color: red}
A.foot:visited {background: transparent; color: black}
Example:
P {color: white ! important} /* increased weight */
P (color: black} /* normal weight */
texttexttext
. P is a parent of STRONG.
BODY {font-size: 10pt}
All text will be displayed in a 10 point font
BODY {font-size: 10pt}
H1 {font-size: 14pt} or H1 {font-size: 180%}
All text except for the level 1 headings will be displayed in a 10 point font. H1 will be displayed in a 14 point font (or in a font that is 80% larger than the one set to BODY). If the element H1 contains other elements, e.g. EM then the EM element will also be displayed in a 14 point font (or 180%) it will inherit the property of the parent H1. If the EM element is to be displayed in some other font then own font properties must be declared to it, as shown below:
BODY {font-size: 10pt}
H1 {font-size: 14pt} or H1 {font-size: 180%}
EM {font-size: 15pt} or EM {font-size: 110%}
The EM element will be displayed in a 15 point font or will be 10% larger than H1. NOTE: EM is, in this example, inside H1 therefore will inherit H1's properties and not BODY's.
H1 EM {font-size: 15pt} or H1 EM {font-size: 110%}
In the example above, EM is a contextual selector. It will be displayed in specified font only if it will be found in the context of H1. /* This is a CSS-comment */