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 }

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 }

CSS TEXT-UNDERLINE-POSITION

Written by jon on 8:19 AM
Sets or retrieves the position of the underline decoration that is set through the textDecoration property of the object.
The auto and auto-pos values apply to this property as of Internet Explorer 6. The default value of this property is auto as of Internet Explorer 6. With Internet Explorer 5.5, the default value of this property is below.

Example
p { text-underline-position: above; text-decoration: underline }

<p style=”text-underline-position: above; text-decoration: underline”>content</p>

Possible Values
Value Description
inherit Explicitly sets the value of this property to that of the parent
length Defines a fixed indentation
% Defines an indentation in % of the width of the parent element

CSS TEXT-INDENT

Written by jon on 8:18 AM
This property specifies the horizontal indent from the left side of the current parent Block Element for the first line in the current Block. The indent is only applied at the beginning of the block and not after any intervening line-breaking elements (like BR.)
Note: Negative values are allowed. The first line will be indented tothe left if the value is negative.

Example
p {text-indent: 18px}

p {text-indent: -11px}

Possible Values
Value Description
inherit Explicitly sets the value of this property to that of the parent
length Defines a fixed indentation
% Defines an indentation in % of the width of the parent element

CSS TEXT-SHADOW

Written by jon on 8:17 AM
This property defines one or more comma-separated shadow effects to be applied to the text content of the current element. Effects consist of a shadow color, a maximum blurring radius for the shadow effect and x/y offset of the shadow effect from the element content. Multiple effects are applied to the element in the order specified in the property. Effects can overlap each other, but they should never overlap the text content.

Example
blockquote { text-shadow: blue 2px 2px, red -2px -2px }
Possible Values
Value Description
inherit Explicitly sets the value of this property to that of the parent
none Defines normal text, with no shadow
[shadow effects] Specifies one or more comma-separated shadow effects for the current element. Effects are given as X/Y offsets along with optional shadow-color and blur-radius values

[Shadow-color]: This uses a color to create the shadow effect and may be placed at the beginning or end of the text-shadow effect syntax (see below.) If no color is specified, the value of the ‘color' property is used.

[Shadow-offset]: This is given as a pair of length values indicating x- and y- distances to use as offset references from the original text content. The first value specifies the horizontal distance of the offset (positive values are to the right, negative values to the left.) The second value specifies the vertical distance of the offset (positive values are below, negative values are above.)

[Blur-radius]: A length value indicating the boundary of the blurring for the current text-shadow effect.


CSS TEXT-TRANSFORM

Written by jon on 8:16 AM
This property sets the casing style for a section of text. Content may not be affected if it is not in the ISO 8859-1 character set or does not have an applicable alternate case character to convert to.

Inherited: Yes

Example
p {text-transform: uppercase}
Possible Values
Value Description
inherit Explicitly sets the value of this property to that of the parent
none Defines normal text, with lower case letters and capital
letters
capitalize Each word in a text starts with a capital letter
uppercase Defines only capital letters
lowercase Defines no capital letters, only lower case letters

CSS TEXT-DECORATION

Written by jon on 8:15 AM
This property describes the appearance characteristics of text that are not specified with the ‘font-style’ and ‘font-weight’ properties. The color of the text-decoration is taken from the ‘color’ property for the element. The characteristics of this property ARE used by child elements if the parent element is set to block. If this property is specified for an element/section containing no text (like the IMG element) or is empty, this property has no effect. Browsers may treat unknown values as underline.

Example
p {text-decoration: underline}
Possible Values
Value Description
inherit Explicitly sets the value of this property to that of the parent
none Defines a normal text
underline Defines a line under the text
overline Defines a line over the text
line-through Defines a line through the text
blink Defines a blinking text

CSS TEXT-ALIGN-LAST

Written by jon on 8:13 AM
This property can be used in conjunction with the ‘text-align’ property, but the value specified overrides the effects of that property on the horizontal alignment of the last or only rendered line of an element.

Example
div { text-align: justify; text-align-last: right}

<div STYLE=”text-align: justify; text-align-last: right”>this
div text is double justified, and the last (or only) line should be right-aligned</div>

Possible Values
Value Description
left Left aligns the content on the last or only rendered line of the element.
right Right aligns the content on the last or only rendered line of the element.
center Center aligns the content on the last or only rendered line of the element.
inherit Explicitly sets the value of this property to that of the parent.
auto Text content on the last line is aligned according to the value of the ‘text-align' property, the default text-alignment for the block or its inherited ‘text-align' value.
justify Applies double text justification to the content on the last or only rendered line of the element.

CSS TEXT-ALIGN

Written by jon on 8:12 AM
The text-align property aligns the text in an element.

Inherited: Yes

Example
p {text-align: center}
Possible Values
Value Description
left Aligns the text to the left
right Aligns the text to the right
center Centers the text
[string] Specifies a string around which cells in a table column will align. Only applies to table cells. If used for other element types, it will be treated as as “left” or “right” depending on the current language writing direction (”left” for English.)
inherit Explicitly sets the value of this property to that of the parent.
justify justified text

CSS WORD-WRAP

Written by jon on 8:11 AM
This property specifies whether the current rendered line should break if the content exceeds the boundary of the specified rendering box for an element (this is similar in some ways to the ‘clip’ and ‘overflow’ properties in intent.) This property should only apply if the element has a visual rendering, is an inline element with explicit height/width, is absolutely positioned and/or is a block element.

Example
div { word-wrap: break-word }

<div style=”word-wrap: break-word”>Here is some content for the div element</div>

Possible Values
Value Description
normal Content will exceed the boundaries of the specified rendering box.
break-word Content will wrap to the next line when necessary, and a word-break will also occur if needed.

CSS WHITE-SPACE

Written by jon on 8:09 AM
Prevent your text from wrapping with nowrap. Note: we have defined the overflow and width CSS attributes, so that you may see nowrap in action.
Example
p {white-space: normal}

<p style=”white-space: normal”>text</p>

Possible Values
Value Description
normal Collapses multiple spaces into one
pre Does not collapse multiple spaces
nowrap Does not allow line wrapping without a tag

CSS LETTER-SPACING

Written by jon on 8:08 AM
Specify the exact value of the spacing between your letters. Letter-spacing works best when pixels are used to define the spacing.

Example
p {letter-spacing: 12px}
p {letter-spacing: -0.5px}
Possible Values
Value Description
normal Defines normal space between characters
length Defines a fixed space between characters

CSS WORD-SPACING

Written by jon on 10:14 AM
Specify the exact value of the spacing between your words. Word-spacing works best when pixels are used as the spacing value.
Examples
p {word-spacing: 30px}
p {word-spacing: -0.5px}
Possible Values
Value Description
normal Defines normal space between words
length Defines a fixed space between words

RECENT COMMENTS

SUBSCRIBE TO CSS3 EXAMPLES

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