Lists: the 'list-style-type', 'list-style-image', 'list-style-position', and 'list-style' properties

Written by jon on 11:53 AM

The list properties allow basic visual formatting of lists. As with more general markers, a element with 'display: list-item' generates a principal box for the element's content and an optional marker box. The other list properties allow authors to specify the marker type (image, glyph, or number) and its position with respect to the principal box (outside it or within it before content). They do not allow authors to specify distinct style (colors, fonts, alignment, etc.) for the list marker or adjust its position with respect to the principal box.

Furthermore, when a marker M (created with 'display: marker') is used with a list item created by the list properties, M replaces the standard list item marker.

With the list properties, the background properties apply to the principal box only; an 'outside' marker box is transparent. Markers offer more control over marker box style.

'list-style-type'
Value: disc | circle | square | decimal | decimal-leading-zero | lower-roman | upper-roman | lower-greek | lower-alpha | lower-latin | upper-alpha | upper-latin | hebrew | armenian | georgian | cjk-ideographic | hiragana | katakana | hiragana-iroha | katakana-iroha | none | inherit
Initial: disc
Applies to: elements with 'display: list-item'
Inherited: yes
Percentages: N/A
Media: visual

This property specifies appearance of the list item marker if 'list-style-image' has the value 'none' or if the image pointed to by the URI cannot be displayed. The value 'none' specifies no marker, otherwise there are three types of marker: glyphs, numbering systems, and alphabetic systems. Note. Numbered lists improve document accessibility by making lists easier to navigate.

Glyphs are specified with disc, circle, and square. Their exact rendering depends on the user agent.

Numbering systems are specified with:

decimal
Decimal numbers, beginning with 1.
decimal-leading-zero
Decimal numbers padded by initial zeros (e.g., 01, 02, 03, ..., 98, 99).
lower-roman
Lowercase roman numerals (i, ii, iii, iv, v, etc.).
upper-roman
Uppercase roman numerals (I, II, III, IV, V, etc.).
hebrew
Traditional Hebrew numbering.
georgian
Traditional Georgian numbering (an, ban, gan, ..., he, tan, in, in-an, ...).
armenian
Traditional Armenian numbering.
cjk-ideographic
Plain ideographic numbers
hiragana
a, i, u, e, o, ka, ki, ...
katakana
A, I, U, E, O, KA, KI, ...
hiragana-iroha
i, ro, ha, ni, ho, he, to, ...
katakana-iroha
I, RO, HA, NI, HO, HE, TO, ...

A user agent that does not recognize a numbering system should use 'decimal'.

Note. This document does not specify the exact mechanism of each numbering system (e.g., how roman numerals are calculated). A future W3C Note may provide further clarifications.

Alphabetic systems are specified with:

lower-latin or lower-alpha
Lowercase ascii letters (a, b, c, ... z).
upper-latin or upper-alpha
Uppercase ascii letters (A, B, C, ... Z).
lower-greek
Lowercase classical Greek alpha, beta, gamma, ... (έ, ή, ί, ...)

This specification does not define how alphabetic systems wrap at the end of the alphabet. For instance, after 26 list items, 'lower-latin' rendering is undefined. Therefore, for long lists, we recommend that authors specify true numbers.

For example, the following HTML document:





Lowercase latin numbering




  1. This is the first item.
  2. This is the second item.
  3. This is the third item.



might produce something like this:

  i This is the first item.

ii This is the second item.
iii This is the third item.

Note that the list marker alignment (here, right justified) depends on the user agent.

Note. Future versions of CSS may provide more complete mechanisms for international numbering styles.

'list-style-image'
Value: | none | inherit
Initial: none
Applies to: elements with 'display: list-item'
Inherited: yes
Percentages: N/A
Media: visual

This property sets the image that will be used as the list item marker. When the image is available, it will replace the marker set with the 'list-style-type' marker.

Example(s):

The following example sets the marker at the beginning of each list item to be the image "ellipse.png".

UL { list-style-image: url("http://png.com/ellipse.png") }

'list-style-position'
Value: inside | outside | inherit
Initial: outside
Applies to: elements with 'display: list-item'
Inherited: yes
Percentages: N/A
Media: visual

This property specifies the position of the marker box in the principal block box. Values have the following meanings:

outside
The marker box is outside the principal block box. Note. CSS1 did not specify the precise location of the marker box and for reasons of compatibility, CSS2 remains equally ambiguous. For more precise control of marker boxes, please use markers.
inside
The marker box is the first inline box in the principal block box, after which the element's content flows.

For example:




Comparison of inside/outside position




  • first list item comes first
  • second list item comes second



  • first list item comes first
  • second list item comes second



The above example may be formatted as:

Counters in elements with 'display: none'

Written by jon on 11:52 AM
An element that is not displayed ('display' set to 'none') cannot increment or reset a counter.

Example(s):

For example, with the following style sheet, H2s with class "secret" do not increment 'count2'.

H2.secret {counter-increment: count2; display: none}

Elements with 'visibility' set to 'hidden', on the other hand, do increment counters.

css Counter styles

Written by jon on 11:51 AM
By default, counters are formatted with decimal numbers, but all the styles available for the 'list-style-type' property are also available for counters. The notation is:

counter(name)

for the default style, or:

counter(name, 'list-style-type')

All the styles are allowed, including 'disc', 'circle', 'square', and 'none'.

Example(s):


H1:before { content: counter(chno, upper-latin) ". " }
H2:before { content: counter(section, upper-roman) " - " }
BLOCKQUOTE:after { content: " [" counter(bq, hebrew) "]" }
DIV.note:before { content: counter(notecntr, disc) " " }
P:before { content: counter(p, none) }

Nested counters and scope

Written by jon on 11:51 AM
Counters are "self-nesting", in the sense that re-using a counter in a child element automatically creates a new instance of the counter. This is important for situations like lists in HTML, where elements can be nested inside themselves to arbitrary depth. It would be impossible to define uniquely named counters for each level.

Example(s):

Thus, the following suffices to number nested list items. The result is very similar to that of setting 'display:list-item' and 'list-style: inside' on the LI element:

OL { counter-reset: item }
LI { display: block }
LI:before { content: counter(item) ". "; counter-increment: item }

The self-nesting is based on the principle that every element that has a 'counter-reset' for a counter X, creates a fresh counter X, the scope of which is the element, its preceding siblings, and all the descendants of the element and its preceding siblings.

In the example above, an OL will create a counter, and all children of the OL will refer to that counter.

If we denote by item[n] the nth instance of the "item" counter, and by "(" and ")" the beginning and end of a scope, then the following HTML fragment will use the indicated counters. (We assume the style sheet as given in the example above).


  1. item
  2. item

    1. item
    2. item
    3. item

      1. item




    4. item

  3. item
  4. item


  1. item
  2. item


The 'counters()' function generates a string composed of the values of all counters with the same name, separated by a given string.

Example(s):


The following style sheet numbers nested list items as "1", "1.1", "1.1.1", etc.

OL { counter-reset: item }
LI { display: block }
LI:before { content: counters(item, "."); counter-increment: item }

Automatic counters and numbering

Written by jon on 11:51 AM
Automatic numbering in CSS2 is controlled with two properties, 'counter-increment' and 'counter-reset'. The counters defined by these properties are used with the counter() and counters() functions of the the 'content' property.

'counter-reset'
Value: [ ? ]+ | none | inherit
Initial: none
Applies to: all elements
Inherited: no
Percentages: N/A
Media: all

'counter-increment'
Value: [ ? ]+ | none | inherit
Initial: none
Applies to: all elements
Inherited: no
Percentages: N/A
Media: all

The 'counter-increment' property accepts one or more names of counters (identifiers), each one optionally followed by an integer. The integer indicates by how much the counter is incremented for every occurrence of the element. The default increment is 1. Zero and negative integers are allowed.

The 'counter-reset' property also contains a list of one or more names of counters, each one optionally followed by an integer. The integer gives the value that the counter is set to on each occurrence of the element. The default is 0.

If 'counter-increment' refers to a counter that is not in the scope (see below) of any 'counter-reset', the counter is assumed to have been reset to 0 by the root element.

Example(s):

This example shows a way to number chapters and sections with "Chapter 1", "1.1", "1.2", etc.

H1:before {
content: "Chapter " counter(chapter) ". ";
counter-increment: chapter; /* Add 1 to chapter */
counter-reset: section; /* Set section to 0 */
}
H2:before {
content: counter(chapter) "." counter(section) " ";
counter-increment: section;
}

If an element increments/resets a counter and also uses it (in the 'content' property of its :before or :after pseudo-element), the counter is used after being incremented/reset.

If an element both resets and increments a counter, the counter is reset first and then incremented.

The 'counter-reset' property follows the cascading rules. Thus, due to cascading, the following style sheet:

H1 { counter-reset: section -1 }
H1 { counter-reset: imagenum 99 }

will only reset 'imagenum'. To reset both counters, they have to be specified together:

H1 { counter-reset: section -1 imagenum 99 }

The 'content' property

Written by jon on 11:50 AM
'content'
Value: [ | | | attr(X) | open-quote | close-quote | no-open-quote | no-close-quote ]+ | inherit
Initial: empty string
Applies to: :before and :after pseudo-elements
Inherited: no
Percentages: N/A
Media: all

This property is used with the :before and :after pseudo-elements to generate content in a document. Values have the following meanings:

">
Text content (see the section on strings).
">
The value is a URI that designates an external resource. If a user agent cannot support the resource because of the media types it supports, it must ignore the resource. Note. CSS2 offers no mechanism to change the size of the embedded object, or to provide a textual description, like the "alt" or "longdesc" attributes do for images in HTML. This may change in future levels of CSS.
">
Counters may be specified with two different functions: 'counter()' or 'counters()'. The former has two forms: 'counter(name)' or 'counter(name, style)'. The generated text is the value of the named counter at this point in the formatting structure; it is formatted in the indicated style ('decimal' by default). The latter function also has two forms: 'counter(name, string)' or 'counter(name, string, style)'. The generated text is the value of all counters with the given name at this point in the formatting structure, separated by the specified string. The counters are rendered in the indicated style ('decimal' by default). See the section on automatic counters and numbering for more information.
open-quote and close-quote
These values are replaced by the appropriate string from the 'quotes' property.
no-open-quote and no-close-quote
Inserts nothing (the empty string), but increments (decrements) the level of nesting for quotes.
attr(X)
This function returns as a string the value of attribute X for the subject of the selector. The string is not parsed by the CSS processor. If the subject of the selector doesn't have an attribute X, an empty string is returned. The case-sensitivity of attribute names depends on the document language. Note. In CSS2, it is not possible to refer to attribute values for other elements of the selector.

The 'display' property controls whether the content is placed in a block, inline, or marker box.

Authors should put 'content' declarations in @media rules when the content is media-sensitive. For instance, literal text may be used for any media group, but images only apply to the visual + bitmap media groups, and sound files only apply to the aural media group.

Example(s):

The following rule causes a sound file to be played at the end of a quotation (see the section on aural style sheets for additional mechanisms):

@media aural {

BLOCKQUOTE:after { content: url("beautiful-music.wav") }
}

Example(s):

The next rule inserts the text of the HTML "alt" attribute before the image. If the image is not displayed, the reader will still see the "alt" text.

IMG:before { content: attr(alt) }

Authors may include newlines in the generated content by writing the "\A" escape sequence in one of the strings after the 'content' property. This inserts a forced line break, similar to the BR element in HTML. See "Strings" and "Characters and case" for more information on the "\A" escape sequence.

Example(s):

H1:before {

display: block;
text-align: center;
content: "chapter\A hoofdstuk\A chapitre"
}

Generated content does not alter the document tree. In particular, it is not fed back to the document language processor (e.g., for reparsing).

Note. In future levels of CSS, the 'content' property may accept additional values, allowing it to vary the style of pieces of the generated content, but in CSS2, all the content of the :before or :after pseudo-element has the same style.

12.3 Interaction of :before and :after with 'compact' and 'run-in' elements

The following cases can occur:

  1. A 'run-in' or 'compact' element has a :before pseudo-element of type 'inline': the pseudo-element is taken into account when the size of the element's box is computed (for 'compact') and is rendered inside the same block box as the element.
  2. A 'run-in' or 'compact' element has an :after pseudo-element of type 'inline': The rules of the previous point apply.
  3. A 'run-in' or 'compact' element has a :before pseudo-element of type 'block': the pseudo-element is formatted as a block above the element, and does not take part in the computation of the element's size (for 'compact').
  4. A 'run-in' or 'compact' element has an :after pseudo-element of type 'block': both the element and its :after pseudo-element are formatted as block boxes. The element is not formatted as an inline box in its own :after pseudo-element.
  5. The element following a 'run-in' or 'compact' element has a :before of type 'block': the decision how to format the 'run-in'/'compact' element is made with respect to the block box resulting from the :before pseudo-element.
  6. The element following a 'run-in' or 'compact' element has an :before of type 'inline': the decision how to format the 'run-in'/'compact' element depends on the 'display' value of the element to which the :before is attached.

Example(s):

Here is an example of a 'run-in' header with an :after pseudo-element, followed by a paragraph with a :before pseudo-element. All pseudo-elements are inline (the default) in this example. When the style sheet:

H3 { display: run-in }

H3:after { content: ": " }
P:before { content: "... " }

is applied to this source document:

Centaurs


have hoofs

have a tail

The visual formatting will resemble:

Centaurs: ... have hoofs

... have a tail

12.4 Quotation marks

In CSS2, authors may specify, in a style-sensitive and context-dependent manner, how user agents should render quotation marks. The 'quotes' property specifies pairs of quotation marks for each level of embedded quotation. The 'content' property gives access to those quotation marks and causes them to be inserted before and after a quotation.

12.4.1 Specifying quotes with the 'quotes' property

'quotes'
Value: [ ]+ | none | inherit
Initial: depends on user agent
Applies to: all elements
Inherited: yes
Percentages: N/A
Media: visual

This property specifies quotation marks for any number of embedded quotations. Values have the following meanings:

none
The 'open-quote' and 'close-quote' values of the 'content' property produce no quotations marks.
["> ">]+
Values for the 'open-quote' and 'close-quote' values of the 'content' property are taken from this list of pairs of quotation marks (opening and closing). The first (leftmost) pair represents the outermost level of quotation, the second pair the first level of embedding, etc. The user agent must apply the appropriate pair of quotation marks according to the level of embedding.

Example(s):

For example, applying the following style sheet:

/* Specify pairs of quotes for two levels in two languages */

Q:lang(en) { quotes: '"' '"' "'" "'" }
Q:lang(no) { quotes: "«" "»" "<" ">" }

/* Insert quotes before and after Q element content */
Q:before { content: open-quote }
Q:after { content: close-quote }

to the following HTML fragment:




Quotes


Quote me!


would allow a user agent to produce:

"Quote me!"

while this HTML fragment:




Quotes


Trøndere gråter når Vinsjan på kaia blir deklamert.


would produce:

«Trøndere gråter når  blir deklamert.»

The :before and :after pseudo-elements

Written by jon on 11:49 AM

For example, the following rule inserts the string "Note: " before the content of every P element whose "class" attribute has the value "note":

P.note:before { content: "Note: " }

The formatting objects (e.g., boxes) generated by an element include generated content. So, for example, changing the above style sheet to:

P.note:before { content: "Note: " }
P.note { border: solid green }

would cause a solid green border to be rendered around the entire paragraph, including the initial string.

The :before and :after pseudo-elements inherit any inheritable properties from the element in the document tree to which they are attached.

Example(s):

For example, the following rules insert an open quote mark before every Q element. The color of the quote mark will be red, but the font will be the same as the font of the rest of the Q element:

Q:before {
content: open-quote;
color: red
}

In a :before or :after pseudo-element declaration, non-inherited properties take their initial values.

Example(s):

So, for example, because the initial value of the 'display' property is 'inline', the quote in the previous example is inserted as an inline box (i.e., on the same line as the element's initial text content). The next example explicitly sets the 'display' property to 'block', so that the inserted text becomes a block:

BODY:after {
content: "The End";
display: block;
margin-top: 2em;
text-align: center;
}

Note that an audio user agent would speak the words "The End" after rendering the rest of the BODY content.

User agents must ignore the following properties with :before and :after pseudo-elements: 'position', 'float', list properties, and table properties.

The :before and :after pseudo-elements elements allow values of the 'display' property as follows:

  • If the subject of the selector is a block-level element, allowed values are 'none', 'inline', 'block', and 'marker'. If the value of the 'display' has any other value, the pseudo-element will behave as if the value were 'block'.
  • If the subject of the selector is an inline-level element, allowed values are 'none' and 'inline'. If the value of the 'display' has any other value, the pseudo-element will behave as if the value were 'inline'.

Whitespace: the 'white-space' property

Written by jon on 11:45 AM
'white-space'
Value: normal | pre | nowrap | inherit
Initial: normal
Applies to: block-level elements
Inherited: yes
Percentages: N/A
Media: visual

This property declares how whitespace inside the element is handled. Values have the following meanings:

normal
This value directs user agents to collapse sequences of whitespace, and break lines as necessary to fill line boxes. Additional line breaks may be created by occurrences of "\A" in generated content (e.g., for the BR element in HTML).
pre
This value prevents user agents from collapsing sequences of whitespace. Lines are only broken at newlines in the source, or at occurrences of "\A" in generated content.
nowrap
This value collapses whitespace as for 'normal', but suppresses line breaks within text except for those created by "\A" in generated content (e.g., for the BR element in HTML).

Example(s):

The following examples show what whitespace behavior is expected from the PRE and P elements, and the "nowrap" attribute in HTML.

PRE        { white-space: pre }
P { white-space: normal }
TD[nowrap] { white-space: nowrap }

Capitalization: the 'text-transform' property

Written by jon on 11:44 AM
'text-transform'
Value: capitalize | uppercase | lowercase | none | inherit
Initial: none
Applies to: all elements
Inherited: yes
Percentages: N/A
Media: visual

This property controls capitalization effects of an element's text. Values have the following meanings:

capitalize
Puts the first character of each word in uppercase.
uppercase
Puts all characters of each word in uppercase.
lowercase
Puts all characters of each word in lowercase.
none
No capitalization effects.

The actual transformation in each case is written language dependent. See RFC 2070 ([RFC2070]) for ways to find the language of an element.

Conforming user agents may consider the value of 'text-transform' to be 'none' for characters that are not from the Latin-1 repertoire and for elements in languages for which the transformation is different from that specified by the case-conversion tables of ISO 10646 ([ISO10646]).

Example(s):

In this example, all text in an H1 element is transformed to uppercase text.

H1 { text-transform: uppercase }

Letter and word spacing: the 'letter-spacing' and 'word-spacing' properties

Written by jon on 11:43 AM
'letter-spacing'
Value: normal | | inherit
Initial: normal
Applies to: all elements
Inherited: yes
Percentages: N/A
Media: visual

This property specifies spacing behavior between text characters. Values have the following meanings:

normal
The spacing is the normal spacing for the current font. This value allows the user agent to alter the space between characters in order to justify text.
">
This value indicates inter-character space in addition to the default space between characters. Values may be negative, but there may be implementation-specific limits. User agents may not further increase or decrease the inter-character space in order to justify text.

Character spacing algorithms are user agent-dependent. Character spacing may also be influenced by justification (see the 'text-align' property).

Example(s):

In this example, the space between characters in BLOCKQUOTE elements is increased by '0.1em'.

BLOCKQUOTE { letter-spacing: 0.1em }

In the following example, the user agent is not permitted to alter inter-character space:

BLOCKQUOTE { letter-spacing: 0cm }   /* Same as '0' */

When the resultant space between two characters is not the same as the default space, user agents should not use ligatures.

Conforming user agents may consider the value of the 'letter-spacing' property to be 'normal'.

'word-spacing'
Value: normal | | inherit
Initial: normal
Applies to: all elements
Inherited: yes
Percentages: N/A
Media: visual

This property specifies spacing behavior between words. Values have the following meanings:

normal
The normal inter-word space, as defined by the current font and/or the UA.
">
This value indicates inter-word space in addition to the default space between words. Values may be negative, but there may be implementation-specific limits.

Word spacing algorithms are user agent-dependent. Word spacing is also influenced by justification (see the 'text-align' property).

Example(s):

In this example, the word-spacing between each word in H1 elements is increased by '1em'.

H1 { word-spacing: 1em }

Conforming user agents may consider the value of the 'word-spacing' property to be 'normal'.

Text shadows: the 'text-shadow' property

Written by jon on 11:43 AM
'text-shadow'
Value: none | [ || ? ,]* [ || ?] | inherit
Initial: none
Applies to: all elements
Inherited: no (see prose)
Percentages: N/A
Media: visual

This property accepts a comma-separated list of shadow effects to be applied to the text of the element. The shadow effects are applied in the order specified and may thus overlay each other, but they will never overlay the text itself. Shadow effects do not alter the size of a box, but may extend beyond its boundaries. The stack level of the shadow effects is the same as for the element itself.

Each shadow effect must specify a shadow offset and may optionally specify a blur radius and a shadow color.

A shadow offset is specified with two "> values that indicate the distance from the text. The first length value specifies the horizontal distance to the right of the text. A negative horizontal length value places the shadow to the left of the text. The second length value specifies the vertical distance below the text. A negative vertical length value places the shadow above the text.

A blur radius may optionally be specified after the shadow offset. The blur radius is a length value that indicates the boundaries of the blur effect. The exact algorithm for computing the blur effect is not specified.

A color value may optionally be specified before or after the length values of the shadow effect. The color value will be used as the basis for the shadow effect. If no color is specified, the value of the 'color' property will be used instead.

Text shadows may be used with the :first-letter and :first-line pseudo-elements.

Example(s):

The example below will set a text shadow to the right and below the element's text. Since no color has been specified, the shadow will have the same color as the element itself, and since no blur radius is specified, the text shadow will not be blurred:

H1 { text-shadow: 0.2em 0.2em }

The next example will place a shadow to the right and below the element's text. The shadow will have a 5px blur radius and will be red.

H2 { text-shadow: 3px 3px 5px red }

The next example specifies a list of shadow effects. The first shadow will be to the right and below the element's text and will be red with no blurring. The second shadow will overlay the first shadow effect, and it will be yellow, blurred, and placed to the left and below the text. The third shadow effect will be placed to the right and above the text. Since no shadow color is specified for the third shadow effect, the value of the element's 'color' property will be used:

H2 { text-shadow: 3px 3px red, yellow -3px 3px 2px, 3px -3px }

Example(s):

Consider this example:

SPAN.glow {
background: white;
color: white;
text-shadow: black 0px 0px 5px;
}

Here, the 'background' and 'color' properties have the same value and the 'text-shadow' property is used to create a "solar eclipse" effect:

Solar eclipse effect [D]

Note. This property is not defined in CSS1. Some shadow effects (such as the one in the last example) may render text invisible in UAs that only support CSS1.

CSS3 Decoration

Written by jon on 11:42 AM

16.3.1 Underlining, overlining, striking, and blinking: the 'text-decoration' property

'text-decoration'
Value: none | [ underline || overline || line-through || blink ] | inherit
Initial: none
Applies to: all elements
Inherited: no (see prose)
Percentages: N/A
Media: visual

This property describes decorations that are added to the text of an element. If the property is specified for a block-level element, it affects all inline-level descendants of the element. If it is specified for (or affects) an inline-level element, it affects all boxes generated by the element. If the element has no content or no text content (e.g., the IMG element in HTML), user agents must ignore this property.

Values have the following meanings:

none
Produces no text decoration.
underline
Each line of text is underlined.
overline
Each line of text has a line above it.
line-through
Each line of text has a line through the middle
blink
Text blinks (alternates between visible and invisible). Conforming user agents are not required to support this value.

The color(s) required for the text decoration should be derived from the 'color' property value.

This property is not inherited, but descendant boxes of a block box should be formatted with the same decoration (e.g., they should all be underlined). The color of decorations should remain the same even if descendant elements have different 'color' values.

Example(s):

In the following example for HTML, the text content of all A elements acting as hyperlinks will be underlined:

A[href] { text-decoration: underline }

Alignment: the 'text-align' property

Written by jon on 11:41 AM
'text-align'
Value: left | right | center | justify | | inherit
Initial: depends on user agent and writing direction
Applies to: block-level elements
Inherited: yes
Percentages: N/A
Media: visual

This property describes how inline content of a block is aligned. Values have the following meanings:

left, right, center, and justify
Left, right, center, and double justify text, respectively.
">
Specifies a string on which cells in a table column will align (see the section on horizontal alignment in a column for details and an example). This value applies only to table cells. If set on other elements, it will be treated as 'left' or 'right', depending on whether 'direction' is 'ltr', or 'rtl', respectively.

A block of text is a stack of line boxes. In the case of 'left', 'right' and 'center', this property specifies how the inline boxes within each line box align with respect to the line box's left and right sides; alignment is not with respect to the viewport. In the case of 'justify', the UA may stretch the inline boxes in addition to adjusting their positions. (See also 'letter-spacing' and 'word-spacing'.)

Example(s):

In this example, note that since 'text-align' is inherited, all block-level elements inside the DIV element with 'class=center' will have their inline content centered.

DIV.center { text-align: center }

Note. The actual justification algorithm used is user-agent and written language dependent.

Conforming user agents may interpret the value 'justify' as 'left' or 'right', depending on whether the element's default writing direction is left-to-right or right-to-left, respectively.

Indentation: the 'text-indent' property

Written by jon on 11:41 AM
'text-indent'
Value: | | inherit
Initial: 0
Applies to: block-level elements
Inherited: yes
Percentages: refer to width of containing block
Media: visual

This property specifies the indentation of the first line of text in a block. More precisely, it specifies the indentation of the first box that flows into the block's first line box. The box is indented with respect to the left (or right, for right-to-left layout) edge of the line box. User agents should render this indentation as blank space.

Values have the following meanings:

">
The indentation is a fixed length.
">
The indentation is a percentage of the containing block width.

The value of 'text-indent' may be negative, but there may be implementation-specific limits.

Example(s):

The following example causes a '3em' text indent.

  P { text-indent: 3em }

Semantic changes from CSS1

Written by jon on 11:40 AM

While all CSS1 style sheets are valid CSS2 style sheets, there are a few cases where the CSS1 style sheet will have a different meaning when interpreted as a CSS2 style sheet. Most changes are due to implementation experience feeding back into the specification, but there are also some error corrections.

  • The meaning of "!important" has been changed. In CSS1, "!important" in an author's style sheet took precedence over one in a user style sheet. This has been reversed in CSS2.
  • In CSS2 color values are clipped with regard to the device gamut, not with regard to the sRGB gamut as in CSS1.
  • CSS1 simply said that 'margin-right' was ignored if the both 'margin-left' and 'width' were set. In CSS2 the choice between relaxing 'margin-right' or 'margin-left' depends on the writing direction.
  • In CSS1, several properties (e.g., 'padding') had values referring to the width of the parent element. This was an error; the value should always refer to the width of a block-level element and this specification reflects this by introducing the term "containing block".
  • The initial value of 'display' is 'inline' in CSS2, not 'block' as in CSS1.
  • In CSS1, the 'clear' property applied to all elements. This was an error, and the property only applies to block-level elements in CSS2.
  • In CSS1, ':link', ':visited' and ':active' were mutually exclusive; in CSS2, ':active' can occur together with ':link' or ':visited'.
  • The suggested scaling factor between adjacent 'font-size' indexes in the table of font sizes has been reduced from 1.5 to 1.2.
  • The computed value, not the actual value, of 'font-size' is inherited.
  • The CSS1 description of 'inside' (for 'list-style-position') allowed the interpretation that the left margin of the text was affected, rather than the position of the bullet. In CSS2 that interpretation is ruled out.
  • Please also consult the normative section on the differences between the CSS1 and CSS2 tokenizer.

CSS3 New functionality

Written by jon on 11:39 AM

In addition to the functionality of CSS1, CSS2 supports:

Comparison of tokenization in CSS2 and CSS1

Written by jon on 11:39 AM

There are some differences in the syntax specified in the CSS1 recommendation ([CSS1]), and the one above. Most of these are due to new tokens in CSS2 that didn't exist in CSS1. Others are because the grammar has been rewritten to be more readable. However, there are some incompatible changes, that were felt to be errors in the CSS1 syntax. They are explained below.

  • CSS1 style sheets could only be in 1-byte-per-character encodings, such as ASCII and ISO-8859-1. CSS2 has no such limitation. In practice, there was little difficulty in extrapolating the CSS1 tokenizer, and some UAs have accepted 2-byte encodings.
  • CSS1 only allowed four hex-digits after the backslash (\) to refer to Unicode characters, CSS2 allows six. Furthermore, CSS2 allows a whitespace character to delimit the escape sequence. E.g., according to CSS1, the string "\abcdef" has 3 letters (\abcd, e, and f), according to CSS2 it has only one (\abcdef).
  • The tab character (ASCII 9) was not allowed in strings. However, since strings in CSS1 were only used for font names and for URLs, the only way this can lead to incompatibility between CSS1 and CSS2 is if a style sheet contains a font family that has a tab in its name.
  • Similarly, newlines (escaped with a backslash) were not allowed in strings in CSS1.
  • CSS2 parses a number immediately followed by an identifier as a DIMEN token (i.e., an unknown unit), CSS1 parsed it as a number and an identifier. That means that in CSS1, the declaration 'font: 10pt/1.2serif' was correct, as was 'font: 10pt/12pt serif'; in CSS2, a space is required before "serif". (Some UAs accepted the first example, but not the second.)
  • In CSS1, a class name could start with a digit (".55ft"), unless it was a dimension (".55in"). In CSS2, such classes are parsed as unknown dimensions (to allow for future additions of new units). To make ".55ft" a valid class, CSS2 requires the first digit to be escaped (".\55ft")

CSS3 Lexical scanner

Written by jon on 11:38 AM

The following is the tokenizer, written in Flex (see [FLEX]) notation. The tokenizer is case-insensitive.

The two occurrences of "\377" represent the highest character number that current versions of Flex can deal with (decimal 255). They should be read as "\4177777" (decimal 1114111), which is the highest possible code point in Unicode/ISO-10646.

%option case-insensitive

h [0-9a-f]
nonascii [\200-\377]
unicode \\{h}{1,6}[ \t\r\n\f]?
escape {unicode}|\\[ -~\200-\377]
nmstart [a-z]|{nonascii}|{escape}
nmchar [a-z0-9-]|{nonascii}|{escape}
string1 \"([\t !#$%&(-~]|\\{nl}|\'|{nonascii}|{escape})*\"
string2 \'([\t !#$%&(-~]|\\{nl}|\"|{nonascii}|{escape})*\'

ident {nmstart}{nmchar}*
name {nmchar}+
num [0-9]+|[0-9]*"."[0-9]+
string {string1}|{string2}
url ([!#$%&*-~]|{nonascii}|{escape})*
w [ \t\r\n\f]*
nl \n|\r\n|\r|\f
range \?{1,6}|{h}(\?{0,5}|{h}(\?{0,4}|{h}(\?{0,3}|{h}(\?{0,2}|{h}(\??|{h})))))

%%

[ \t\r\n\f]+ {return S;}

\/\*[^*]*\*+([^/][^*]*\*+)*\/ /* ignore comments */

"" {return CDC;}
"~=" {return INCLUDES;}
"|=" {return DASHMATCH;}

{string} {return STRING;}

{ident} {return IDENT;}

"#"{name} {return HASH;}

"@import" {return IMPORT_SYM;}
"@page" {return PAGE_SYM;}
"@media" {return MEDIA_SYM;}
"@font-face" {return FONT_FACE_SYM;}
"@charset" {return CHARSET_SYM;}
"@"{ident} {return ATKEYWORD;}

"!{w}important" {return IMPORTANT_SYM;}

{num}em {return EMS;}
{num}ex {return EXS;}
{num}px {return LENGTH;}
{num}cm {return LENGTH;}
{num}mm {return LENGTH;}
{num}in {return LENGTH;}
{num}pt {return LENGTH;}
{num}pc {return LENGTH;}
{num}deg {return ANGLE;}
{num}rad {return ANGLE;}
{num}grad {return ANGLE;}
{num}ms {return TIME;}
{num}s {return TIME;}
{num}Hz {return FREQ;}
{num}kHz {return FREQ;}
{num}{ident} {return DIMEN;}
{num}% {return PERCENTAGE;}
{num} {return NUMBER;}

"url("{w}{string}{w}")" {return URI;}
"url("{w}{url}{w}")" {return URI;}
{ident}"(" {return FUNCTION;}

U\+{range} {return UNICODERANGE;}
U\+{h}{1,6}-{h}{1,6} {return UNICODERANGE;}

. {return *yytext;}

CSS3 Grammar

Written by jon on 11:38 AM

The grammar below is LL(1) (but note that most UA's should not use it directly, since it doesn't express the parsing conventions, only the CSS2 syntax). The format of the productions is optimized for human consumption and some shorthand notation beyond Yacc (see [YACC]) is used:

  • *: 0 or more
  • +: 1 or more
  • ?: 0 or 1
  • |: separates alternatives
  • [ ]: grouping

The productions are:

stylesheet
: [ CHARSET_SYM S* STRING S* ';' ]?
[S|CDO|CDC]* [ import [S|CDO|CDC]* ]*
[ [ ruleset | media | page | font_face ] [S|CDO|CDC]* ]*
;
import
: IMPORT_SYM S*
[STRING|URI] S* [ medium [ ',' S* medium]* ]? ';' S*
;
media
: MEDIA_SYM S* medium [ ',' S* medium ]* '{' S* ruleset* '}' S*
;
medium
: IDENT S*
;
page
: PAGE_SYM S* IDENT? pseudo_page? S*
'{' S* declaration [ ';' S* declaration ]* '}' S*
;
pseudo_page
: ':' IDENT
;
font_face
: FONT_FACE_SYM S*
'{' S* declaration [ ';' S* declaration ]* '}' S*
;
operator
: '/' S* | ',' S* | /* empty */
;
combinator
: '+' S* | '>' S* | /* empty */
;
unary_operator
: '-' | '+'
;
property
: IDENT S*
;
ruleset
: selector [ ',' S* selector ]*
'{' S* declaration [ ';' S* declaration ]* '}' S*
;
selector
: simple_selector [ combinator simple_selector ]*
;
simple_selector
: element_name? [ HASH | class | attrib | pseudo ]* S*
;
class
: '.' IDENT
;
element_name
: IDENT | '*'
;
attrib
: '[' S* IDENT S* [ [ '=' | INCLUDES | DASHMATCH ] S*
[ IDENT | STRING ] S* ]? ']'
;
pseudo
: ':' [ IDENT | FUNCTION S* IDENT S* ')' ]
;
declaration
: property ':' S* expr prio?
| /* empty */
;
prio
: IMPORTANT_SYM S*
;
expr
: term [ operator term ]*
;
term
: unary_operator?
[ NUMBER S* | PERCENTAGE S* | LENGTH S* | EMS S* | EXS S* | ANGLE S* |
TIME S* | FREQ S* | function ]
| STRING S* | IDENT S* | URI S* | RGB S* | UNICODERANGE S* | hexcolor
;
function
: FUNCTION S* expr ')' S*
;
/*
* There is a constraint on the color that it must
* have either 3 or 6 hex-digits (i.e., [0-9a-fA-F])
* after the "#"; e.g., "#000" is OK, but "#abcd" is not.
*/
hexcolor
: HASH S*
;

Visibility: the 'visibility' property

Written by jon on 11:36 AM
'visibility'
Value: visible | hidden | collapse | inherit
Initial: inherit
Applies to: all elements
Inherited: no
Percentages: N/A
Media: visual

The 'visibility' property specifies whether the boxes generated by an element are rendered. Invisible boxes still affect layout (set the 'display' property to 'none' to suppress box generation altogether). Values have the following meanings:

visible
The generated box is visible.
hidden
The generated box is invisible (fully transparent), but still affects layout.
collapse
Please consult the section on dynamic row and column effects in tables. If used on elements other than rows or columns, 'collapse' has the same meaning as 'hidden'.

This property may be used in conjunction with scripts to create dynamic effects.

In the following example, pressing either form button invokes a user-defined script function that causes the corresponding box to become visible and the other to be hidden. Since these boxes have the same size and position, the effect is that one replaces the other. (The script code is in a hypothetical script language. It may or may not have any effect in a CSS-capable UA.)








Choose a suspect:



Al Capone width="100" height="100"
src="suspect1.jpg" />

Name: Al Capone


Residence: Chicago





Lucky Luciano width="100" height="100"
src="suspect2.jpg" />

Name: Lucky Luciano


Residence: New York




action="http://www.suspect.org/process-bums">


value="Capone"
onclick='show("container1");hide("container2")'>
value="Luciano"
onclick='show("container2");hide("container1")'>




RECENT COMMENTS

SUBSCRIBE TO CSS3 EXAMPLES

 Subscribe to css3 Examples via RSS
Or, subscribe via email:
Find CSS3 Examples Entries :