Markers and lists
0Most block-level elements in CSS generate one principal block box. In this section, we discuss two CSS mechanisms that cause an element to generate two boxes: one principal block box (for the element’s content) and one separate marker box (for decoration such as a bullet, image, or number). The marker box may be positioned inside or outside the principal box. Unlike :before and :after content, the marker box does not affect the position of the principal box, whatever the positioning scheme.
The more general of the two mechanisms is new in CSS2 and is called markers. The more limited mechanism involves the list properties of CSS1. The list properties give authors quick results for many common ordered and unordered list scenarios. However, markers give authors precise control over marker content and position. Markers may be used with counters to create new list styles, to number margin notes, and much More >
Lists: the ‘list-style-type’, ‘list-style-image’, ‘list-style-position’, and ‘list-style’ properties
0The 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. More >
Counters in elements with ‘display: none’
0An 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.
Nested counters and scope
0Counters 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 More >
css Counter styles
0By 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) }
Automatic counters and numbering
0Automatic 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 More >
The ‘content’ property
0This 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.
The :before and :after pseudo-elements
0For 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.
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
