Styling ordered list numbers with CSS is not as simple as one might think because there is no CSS selector to target list numbers. Styling them is only possible with a simple CSS3 technique that uses a counter to replace the default numbers.
Styled numbers will only be visible in CSS3 browsers , but fallback is provided so that default unstyled numbers are displayed in old browsers.
<ol> CSS styling
CSS counters are variables which are incremented using CSS rules. By reseting a counter on every ol tag and then incrementing it on every li tag, we replicate the list numbering. Then simply set the li's content as the counter value. To create your own ol CSS styles start with:
[css][/css] To use roman numerals change the content rule to <code>content: counter(ol-counter, upper-roman);</code> (for I,II,III,IV...). For letters, use lower-alpha (a,b,c,d...) or upper-alpha (A,B,C,D...). With the above code, no numbers are displayed in browsers that don't support counters, like Internet Explorer 7 and below. Add the line <code>list-style-type: decimal !ie;</code> for a normal unstyled list to be displayed in IE7-. <h2>Some <ol> styles</h2> I leave you some <ol> CSS styles I created using the technique explained above. Feel free to copy and modify them, or use the code as is. All the examples make use of the IE7- hack to show an unstyled list. Removing the IE7- hack future-proofs the code (in case the line is read by a new browser, breaking the hack), but then no numbers will be displayed by those browsers. <h3 style="color: #141412;">Simple</h3> <p style="color: #141412;">Simple. Just a number and a border:</p> <p style="color: #141412;"><img class="aligncenter size-full wp-image-998 nopin" src="http://codeitdown.com/wp-content/uploads/2014/02/simple-ol-css-style.png" alt="Simple ordered list style" width="600" height="auto" /></p> [css]ol.simple-list { list-style-type: none; list-style-type: decimal !ie; /*IE 7- hack*/ margin: 0; margin-left: 3em; padding: 0; counter-reset: li-counter; } ol.simple-list > li{ position: relative; margin-bottom: 20px; padding-left: 0.5em; min-height: 3em; border-left: 2px solid #CCCCCC; } ol.simple-list > li:before { position: absolute; top: 0; left: -1em; width: 0.8em; font-size: 3em; line-height: 1; font-weight: bold; text-align: right; color: #464646; content: counter(li-counter); counter-increment: li-counter; }[/css]Tilted
Tilted and partially covered numbers. Depending on your font, you may need to change the left propery of the pseudo-element to adjust the look.
[css]ol.tilted-list { list-style-type: none; list-style-type: decimal !ie; /*IE 7- hack*/ margin: 0; margin-left: 3em; padding: 0; counter-reset: li-counter; } ol.tilted-list > li{ position: relative; margin-bottom: 20px; padding: 1em; border-left: 2px solid #CCCCCC; background-color: #f5f5f5; } ol.tilted-list > li:before { position: absolute; top: 0; left: -0.95em; width: 1em; font-size: 4em; line-height: 1; font-weight: bold; text-align: right; color: #464646; transform: rotate(-25deg); -ms-transform: rotate(-25deg); -webkit-transform: rotate(-25deg); z-index: -99; overflow: hidden; content: counter(li-counter); counter-increment: li-counter; }[/css]Circles
Circles look great in color. Change border and background colors to fit your theme. Adding box shadow might engance the look. [css]ol.circles-list { list-style-type: none; list-style-type: decimal !ie; /*IE 7- hack*/ margin: 0; margin-left: 4em; padding: 0; counter-reset: li-counter; } ol.circles-list > li{ position: relative; margin-bottom: 20px; padding-left: 0.5em; min-height: 3em; } ol.circles-list > li:before { position: absolute; top: 0; left: -1.33em; width: 1.2em; height: 1.2em; font-size: 2.5em; line-height: 1.2; text-align: center; color: #f5f5f5; border: 3px solid #c5c5c5; border-radius: 50%; background-color: #464646; content: counter(li-counter); counter-increment: li-counter; }[/css]Boxes
[css]ol.boxes-list { list-style-type: none; list-style-type: decimal !ie; /*IE 7- hack*/ margin: 0; margin-left: 3em; padding: 0; counter-reset: li-counter; } ol.boxes-list > li{ position: relative; margin-bottom: 15px; padding: 1em; background-color: #d5d5d5; } ol.boxes-list > li:before { position: absolute; top: 0; left: -1em; width: 0.94em; height: 0.94em; font-size: 3em; line-height: 0.94; text-align: center; color: #f5f5f5; background-color: #464646; content: counter(li-counter); counter-increment: li-counter; }[/css]Revisions
- September 2, 2015 @ 14:25:43 [Current Revision] by PeterLugg
- September 2, 2015 @ 14:25:43 by PeterLugg
- April 29, 2014 @ 14:23:55 by PeterLugg
- April 29, 2014 @ 14:22:29 by PeterLugg
- April 29, 2014 @ 14:22:00 by PeterLugg
Revision Differences
April 29, 2014 @ 14:22:29 | Current Revision | ||
---|---|---|---|
Content | |||
Unchanged: Original here: <a href="http:// codeitdown.com/ ordered-list- css-styles/" target="_blank" >http://codeitdown.com/ordered- list-css-styles/</a> | Unchanged: Original here: <a href="http:// codeitdown.com/ ordered-list- css-styles/" target="_blank" >http://codeitdown.com/ordered- list-css-styles/</a> | ||
Unchanged: <p style="color: #141412;">Styling ordered list numbers with CSS is not as simple as one might think because there is no CSS selector to target list numbers. Styling them is only possible with a simple CSS3 technique that uses a counter to replace the default numbers.</p> | Unchanged: <p style="color: #141412;">Styling ordered list numbers with CSS is not as simple as one might think because there is no CSS selector to target list numbers. Styling them is only possible with a simple CSS3 technique that uses a counter to replace the default numbers.</p> | ||
Unchanged: <p style="color: #141412;">Styled numbers will only be visible in CSS3 browsers , but fallback is provided so that default unstyled numbers are displayed in old browsers.</p> | Unchanged: <p style="color: #141412;">Styled numbers will only be visible in CSS3 browsers , but fallback is provided so that default unstyled numbers are displayed in old browsers.</p> | ||
Unchanged: <h2 style="color: #141412;"><ol> CSS styling</h2> | Unchanged: <h2 style="color: #141412;"><ol> CSS styling</h2> | ||
Unchanged: <p style="color: #141412;">CSS counters are variables which are incremented using CSS rules. By reseting a counter on every ol tag and then incrementing it on every li tag, we replicate the list numbering. Then simply set the li's content as the counter value. To create your own ol CSS styles start with:</p> | Unchanged: <p style="color: #141412;">CSS counters are variables which are incremented using CSS rules. By reseting a counter on every ol tag and then incrementing it on every li tag, we replicate the list numbering. Then simply set the li's content as the counter value. To create your own ol CSS styles start with:</p> | ||
Unchanged: [css][/css] | Unchanged: [css][/css] | ||
Deleted: To use roman numerals change the content rule to <code>content: counter(ol-counter, upper-roman); </code> (for I,II,III,IV...). For letters, use lower-alpha (a,b,c,d...) or upper-alpha (A,B,C,D...). With the above code, no numbers are displayed in browsers that don't support counters, like Internet Explorer 7 and below. Add the line <code>list-style-type: decimal !ie;</code> for a normal unstyled list to be displayed in IE7-. | |||
Added: To use roman numerals change the content rule to <code>content: counter(ol-counter, upper-roman); </code> (for I,II,III,IV...). For letters, use lower-alpha (a,b,c,d...) or upper-alpha (A,B,C,D...). With the above code, no numbers are displayed in browsers that don't support counters, like Internet Explorer 7 and below. Add the line <code> list-style-type: decimal !ie;</code> for a normal unstyled list to be displayed in IE7-. <h2>Some &lt;ol&gt; styles</h2> I leave you some &lt;ol&gt; CSS styles I created using the technique explained above. Feel free to copy and modify them, or use the code as is. All the examples make use of the IE7- hack to show an unstyled list. Removing the IE7- hack future-proofs the code (in case the line is read by a new browser, breaking the hack), but then no numbers will be displayed by those browsers. <h3 style="color: #141412;"> Simple</h3> <p style="color: #141412;">Simple. Just a number and a border:</p> <p style="color: #141412;"><img class="aligncenter size-full wp-image-998 nopin" src="http://codeitdown.com/ wp-content/uploads/2014/02/ simple-ol-css-style.png" alt="Simple ordered list style" width="600" height="auto" /></p> | |||
Added: [css]ol.simple-list { | |||
Added: list-style-type: none; | |||
Added: list-style-type: decimal !ie; /*IE 7- hack*/ | |||
Added: margin: 0; | |||
Added: margin-left: 3em; | |||
Added: padding: 0; | |||
Added: counter-reset: li-counter; | |||
Added: } | |||
Deleted: <h2>Some <ol> styles</h2> | Added: ol.simple-list > li{ | ||
Deleted: I leave you some <ol> CSS styles I created using the technique explained above. Feel free to copy and modify them, or use the code as is. | |||
Deleted: All the examples make use of the IE7- hack to show an unstyled list. Removing the IE7- hack future-proofs the code (in case the line is read by a new browser, breaking the hack), but then no numbers will be displayed by those browsers. | |||
Deleted: <h3 style="color: #141412;">Simple</h3> | |||
Deleted: <p style="color: #141412;">Simple. Just a number and a border:</p> | |||
Deleted: <p style="color: #141412;"><img class="aligncenter size-full wp-image-998 nopin" src="http://codeitdown.com/ wp-content/uploads/2014/02/ simple-ol-css-style.png" alt="Simple ordered list style" width="600" height="auto" /></p> | |||
Added: position: relative; | |||
Added: margin-bottom: 20px; | |||
Added: padding-left: 0.5em; | |||
Added: min-height: 3em; | |||
Added: border-left: 2px solid #CCCCCC; | |||
Added: } | |||
Added: ol.simple-list > li:before { | |||
Added: position: absolute; | |||
Added: top: 0; | |||
Added: left: -1em; | |||
Added: width: 0.8em; | |||
Added: font-size: 3em; | |||
Added: line-height: 1; | |||
Added: font-weight: bold; | |||
Added: text-align: right; | |||
Added: color: #464646; | |||
Added: content: counter(li-counter); | |||
Added: counter-increment: li-counter; | |||
Deleted: | Added: }[/css] | ||
Unchanged: <h3 style="color: #141412;">Tilted</h3> | Unchanged: <h3 style="color: #141412;">Tilted</h3> | ||
Unchanged: <p style="color: #141412;">Tilted and partially covered numbers. Depending on your font, you may need to change the left propery of the pseudo-element to adjust the look.</p> | Unchanged: <p style="color: #141412;">Tilted and partially covered numbers. Depending on your font, you may need to change the left propery of the pseudo-element to adjust the look.</p> | ||
Deleted: <p style="color: #141412;"><img class="aligncenter size-full wp-image-998 nopin" src="http:// | Added: <p style="color: #141412;"><img class="aligncenter size-full wp-image-998 nopin" src="http://wiki.pixelpress.com.au/ files/2014/04/ tilted-ol-css-style.png" alt="Tilted ordered list style" width="600" height="auto" /></p> | ||
Added: [css]ol.tilted-list { | |||
Added: list-style-type: none; | |||
Added: list-style-type: decimal !ie; /*IE 7- hack*/ | |||
Added: margin: 0; | |||
Added: margin-left: 3em; | |||
Added: padding: 0; | |||
Added: counter-reset: li-counter; | |||
Added: } | |||
Added: ol.tilted-list > li{ | |||
Added: position: relative; | |||
Added: margin-bottom: 20px; | |||
Added: padding: 1em; | |||
Added: border-left: 2px solid #CCCCCC; | |||
Added: background-color: #f5f5f5; | |||
Added: } | |||
Added: ol.tilted-list > li:before { | |||
Added: position: absolute; | |||
Added: top: 0; | |||
Added: left: -0.95em; | |||
Added: width: 1em; | |||
Added: font-size: 4em; | |||
Added: line-height: 1; | |||
Added: font-weight: bold; | |||
Added: text-align: right; | |||
Added: color: #464646; | |||
Added: transform: rotate(-25deg); | |||
Added: -ms-transform: rotate(-25deg); | |||
Added: -webkit-transform: rotate(-25deg); | |||
Added: z-index: -99; | |||
Added: overflow: hidden; | |||
Added: content: counter(li-counter); | |||
Added: counter-increment: li-counter; | |||
Deleted: | Added: }[/css] | ||
Unchanged: <h3>Circles</h3> | Unchanged: <h3>Circles</h3> | ||
Unchanged: Circles look great in color. Change border and background colors to fit your theme. Adding box shadow might engance the look. | Unchanged: Circles look great in color. Change border and background colors to fit your theme. Adding box shadow might engance the look. | ||
Deleted: <img class="aligncenter size-full wp-image-998 nopin" src="http:// | Added: <img class="aligncenter size-full wp-image-998 nopin" src="http://wiki.pixelpress.com.au/ files/2014/04/circles-ol- css-style.png" alt="Circles ordered list style" width="600" height="auto" /> | ||
Added: [css]ol.circles-list { | |||
Added: list-style-type: none; | |||
Added: list-style-type: decimal !ie; /*IE 7- hack*/ | |||
Added: margin: 0; | |||
Added: margin-left: 4em; | |||
Added: padding: 0; | |||
Added: counter-reset: li-counter; | |||
Added: } | |||
Added: ol.circles-list > li{ | |||
Added: position: relative; | |||
Added: margin-bottom: 20px; | |||
Added: padding-left: 0.5em; | |||
Added: min-height: 3em; | |||
Added: } | |||
Added: ol.circles-list > li:before { | |||
Added: position: absolute; | |||
Added: top: 0; | |||
Added: left: -1.33em; | |||
Added: width: 1.2em; | |||
Added: height: 1.2em; | |||
Added: font-size: 2.5em; | |||
Added: line-height: 1.2; | |||
Added: text-align: center; | |||
Added: color: #f5f5f5; | |||
Added: border: 3px solid #c5c5c5; | |||
Added: border-radius: 50%; | |||
Added: background-color: #464646; | |||
Added: content: counter(li-counter); | |||
Added: counter-increment: li-counter; | |||
Deleted: | Added: }[/css] | ||
Unchanged: <h3 style="color: #141412;">Boxes</h3> | Unchanged: <h3 style="color: #141412;">Boxes</h3> | ||
Deleted: <p style="color: #141412;"><img class="aligncenter size-full wp-image-998 nopin" src="http:// | Added: <p style="color: #141412;"><img class="aligncenter size-full wp-image-998 nopin" src="http://wiki.pixelpress.com.au/ files/2014/04/ boxes-ol-css-style.png" alt="Boxes ordered list style" width="600" height="auto" /></p> | ||
Added: [css]ol.boxes-list { | |||
Added: list-style-type: none; | |||
Added: list-style-type: decimal !ie; /*IE 7- hack*/ | |||
Added: margin: 0; | |||
Added: margin-left: 3em; | |||
Added: padding: 0; | |||
Added: counter-reset: li-counter; | |||
Added: } | |||
Added: ol.boxes-list > li{ | |||
Added: position: relative; | |||
Added: margin-bottom: 15px; | |||
Added: padding: 1em; | |||
Added: background-color: #d5d5d5; | |||
Added: } | |||
Added: ol.boxes-list > li:before { | |||
Added: position: absolute; | |||
Added: top: 0; | |||
Added: left: -1em; | |||
Added: width: 0.94em; | |||
Added: height: 0.94em; | |||
Added: font-size: 3em; | |||
Added: line-height: 0.94; | |||
Added: text-align: center; | |||
Added: color: #f5f5f5; | |||
Added: background-color: #464646; | |||
Added: content: counter(li-counter); | |||
Added: counter-increment: li-counter; | |||
Deleted: | Added: }[/css] | ||
Deleted: |
Note: Spaces may be added to comparison text to allow better line wrapping.
No comments yet.