How to increase size of serial number in OL - html

I want to increase the size of the number in OL without increasing the font size of the text of the content.
What is wrong with this and how to correct it:
<ol style="font-size:5em">
<li style="font-size:1em">Hello </li>
</ol>
All I want is big number 1 with font-size of 5em with 1em text size of the content Hello.
Also I need to use only inline style.

The numbers of the li elements are formatted according to the CSS rules for the li elements themselves; therefore to style the numbers differently to the text you have to wrap the text itself into another element (in this case a span):
<ol>
<li><span>list element one</span></li>
<li><span>list element two</span></li>
</ol>
CSS:
li {
list-style: decimal-leading-zero;
font-size: 5em;
margin: 0 0 0 2em;
}
li span {
font-size: 0.25em;
}
li {
list-style: decimal-leading-zero;
font-size: 5em;
margin: 0 0 0 2em;
}
li span {
font-size: 0.25em;
}
<ol>
<li><span>list element one</span>
</li>
<li><span>list element two</span>
</li>
</ol>
JS Fiddle demo.
If you're able to sacrifice certain older browsers that can't handle generated content, then you could use, instead:
<ol>
<li>list element one</li>
<li>list element two</li>
</ol>
and:
ol {
counter-reset: listNumbering;
}
li {
font-size: 1em;
counter-increment: listNumbering;
}
li:before {
content: counter(listNumbering,decimal-leading-zero) '.';
font-size: 5em;
}
ol {
list-style-type: none;
counter-reset: listNumbering;
}
li {
font-size: 1em;
counter-increment: listNumbering;
}
li:before {
content: counter(listNumbering, decimal-leading-zero)'.';
font-size: 5em;
}
<ol>
<li>list element one</li>
<li>list element two</li>
</ol>
JS Fiddle demo.
Revisiting this answer, it seems that the ::marker pseudo-element is beginning to be more widely adopted (albeit behind flags in Chrome and Edge 80+, as of writing). This means it may be a better option than the above in the relatively near future:
li {
/* something of a magic number to position the ::marker
on the page: */
margin-left: 2em;
}
/* the generated list-marker for the <li> element: */
li::marker {
color: #f90;
font-size: 5em;
}
Please note that the below snippet – and the above CSS – requires a compatible browser, some browsers such as Chrome, Chromium and Edge in versions 80 and above require that enable-experimental-web-platform-features flag be enabled, whereas in Firefox 68+ it should work).
li {
margin-left: 2em;
}
::marker {
color: #f90;
font-size: 5em;
}
<ol>
<li>list element one</li>
<li>list element two</li>
</ol>
JS Fiddle demo.
References:
counter().
counter-increment.
counter-reset.
::marker pseudo-element (compatibility).

You can use the CSS pseudo-element ::marker. (Demo snippet below.)
ol li::marker {
font-size: 2em;
}
ol li::marker {
font-size: 2em;
color: red;
}
<ol>
<li>Hello</li>
</ol>

See this tutorial.
ol {
font: 5em;
}
ol p {
font: 1em;
}

Try something like this:
<ol>
<li style="font-size: 3em"><span style="font-size: .5em">Hello</span></li>
</ol>

Related

CSS: How can I select all ul tags contained within ol tags

My HTML looks like
<ol class='enlarge'>
<li>Larger
<ul>
<li>Normal
</li>
</ul>
</li>
</ol>
Where you see Larger I want the font size to be larger. And where you see Normal, I want the font size to be normal.
I've tried
ol.enlarge {
font-size: 130%;
}
ul.enlarge {
font-size: 70%;
}
And
ol {
font-size: 130%;
}
ul > ol {
font-size: 70%;
}
And
ol {
font-size: 130%;
}
ol > ul {
font-size: 70%;
}
All are setting the font size bigger for everything in my <ol>
Thanks!
-Tom
ol ul should be sufficient to target elements needed for reduced font-sizes.
ol {
font-size: 130%;
}
ol ul {
font-size: 70%;
}
<ol>
<li>Larger
<ul>
<li>Normal</li>
</ul>
</li>
</ol>
Another idea is to use ol > li > ul {...} instead of ol > ul {...}. Anyway, this depends on the markup that you are planning to use. Just keep in mind that > means direct child and this is the reason why ol > ul didn't work.
ol {
font-size: 130%;
}
ol > li > ul {
font-size: 70%;
}
<ol>
<li>Larger
<ul>
<li>Normal
</li>
</ul>
</li>
</ol>
You are looking for a descendant combinator. Select any ul element within ol element.
ol {
font-size: 130%;
}
ol ul {
font-size: 70%;
}
<ol>
<li>Larger
<ul>
<li>Normal
</li>
</ul>
</li>
</ol>
Why did your attempts failed?
Case 1:
You were missing the class enlarge in your markup:
ol.enlarge {
font-size: 130%;
}
ul.enlarge {
font-size: 70%;
}
<ol class="enlarge">
<li>Larger
<ul class="enlarge">
<li>Normal
</li>
</ul>
</li>
</ol>
Case 2:
There is no ordered list element (ol) as a direct child, that's why the child combinator does not work. Notice that an ol element cannot be a direct child of an ul element according to semantic HTML.
ol {
font-size: 130%;
}
ul>ol {
font-size: 70%;
}
<ol>
<li>Larger
<ul>
<ol>Invalid</ol>
<li>Normal
</li>
</ul>
</li>
</ol>
Case 3:
Similar to the case above, there is no ul element as a direct child of an ol element. Which again, it is not a valid markup.
ol {
font-size: 130%;
}
ol>ul {
font-size: 70%;
}
<ol>
<ul>Invalid</ul>
<li>Larger
<ul>
<li>Normal
</li>
</ul>
</li>
</ol>
Not sure If I fully understand you, but what about this.
OL LI { font-size: 130%; }
UL LI { font-size: 70%; }

text in <span> is not inheriting styles from class

I wonder if someone can help me or point me in the right direction so I can resolve my problem.
I have a list which has got class assigned
<ul class="link-list nav">
<li>Menu 1</li>
<li>Menu 2</li>
<li>Menu 3</li>
<li>Menu 4</li>
</ul>
The link-list nav looks as below:
.link-list {
display: inline-block;
list-style: none;
margin: 0;
padding: 0;
font-size: 12px;
}
.link-list > li {
display: inline-block;
}
.link-list > li > a {
display: block;
padding: .9em 1.6em;
/*margin: top right bottom left;
border: 1px solid white;*/
text-decoration: none;
color: white;
}
.link-list > li > a:hover { /* :hover, :focus, :blur */
color: pink;
}
.link-list.nav > li > a {
font-weight: bold;
}
So now the list is being formatted as it should be
Correct colors:
but when I am trying to make the first item of the list bigger by embedding span tags and changing above code to:
<ul class="link-list nav">
<li><span style="font-size: large">Menu 1</span></li>
<li>Menu 2</li>
<li>Menu 3</li>
<li>Menu 4</li>
</ul>
The font become bigger but also all other formatting disappear
Incorrect colors:
I have been experimenting with defining another class which would inherit from link-list nav but unsuccessfully. Any suggestions please?
Thanks in advance,
Regards Tom.
you can put the span as child of a given your CSS (you are using the direct child selector >).
or
you can just use CSS selector first-child in li
or
or simply removing the >, making it a child (not direct one).
.link-list {
display: inline-block;
list-style: none;
margin: 0;
padding: 0;
font-size: 12px;
}
.link-list > li {
display: inline-block;
}
.link-list > li > a {
display: block;
padding: .9em 1.6em;
/*margin: top right bottom left;
border: 1px solid white;*/
text-decoration: none;
color: red;
}
.link-list > li > a:hover {
/* :hover, :focus, :blur */
color: pink;
}
.link-list.nav > li > a {
font-weight: 700;
}
/* use this */
.link-list.nav > li > a span {
font-size: 20px
}
/* or use this */
.link-list.nav > li:first-child > a {
color: blue
}
<ul class="link-list nav">
<li><span>Menu 1</span>
</li>
<li>Menu 2
</li>
<li>Menu 3
</li>
<li>Menu 4
</li>
</ul>
The selectors no longer match because the <a> is no longer a child of the <li>.
Use a descendant combinator (a space) instead of a child combinator (a >).
Alternatively, put the span inside the innermost element so that it doesn't disrupt the child combinators.
Alternatively, and probably the best option, don't add an extra element at all. You want to style all the text there, so apply your CSS to the whole element.
Thank you Quentin and dippas for your swift responses.
Out of both solutions, I have gone for creating:
.link-list.nav > li > a span {
font-size: 20px
}
and changing
<li><span>Menu 1</span>
to
<li><span>Menu 1</span>
This resolved my problem completely.
Clearly I need to reach out to articles about inheriting.
Thanks again and take care guys!

HTML - ordered list, styling the list numbers like (a), (i), (aa)

I have attached my HTML and CSS file.
What I need: the "a." should be enclosed within () like (a) and the "i" in the next level as (i) and under the "i" the list number shown as "1" should be displayed as (aa) next as (ab) and so on.
I want the alignment to remain as it is and only the styling to change inline with my expectations. How to do this?
Note: The solution shouldn't cause change in alignment and JavaScript isn't allowed
p.p1 {
text-indent: 0cm;
margin-left: 36;
word-break: break-all;
}
li {
list-style-position: inside;
margin-top: 10pt;
word-break: break-all;
}
li::before {
content: "";
width: 13pt;
display: inline-block;
}
.ol1 {
padding-left: 2pt;
}
.pNote {
text-indent: 0cm;
margin: 0cm 0cm 10pt;
}
<ol class="ol1">
<li>FirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirst
<ol type="a">
<li>Bullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-a
<ol type="i">
<li>Bullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-i
</li>
<ol type="aa">
<li>Bullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aa
</li>
<li>
Bullet-abBullet-abBullet-abBullet-abBullet-abBullet-abBullet-abBullet-abBullet-abBullet-abBullet-abBullet-abBullet-abBullet-abBullet-abBullet-abBullet-abBullet-abBullet-abBullet-abBullet-abBullet-abBullet-abBullet-abBullet-abBullet-abBullet-abBullet-abBullet-ab
</li>
</ol>
<li>
Bullet-iiBullet-iiBullet-iiBullet-iiBullet-iiBullet-iiBullet-iiBullet-iiBullet-iiBullet-iiBullet-iiBullet-iiBullet-iiBullet-iiBullet-iiBullet-iiBullet-iiBullet-iiBullet-iiBullet-iiBullet-iiBullet-iiBullet-iiBullet-iiBullet-iiBullet-iiBullet-iiBullet-iiBullet-iiBullet-iiBullet-iiBullet-ii
</li>
</ol>
</li>
<li>
Bullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-b
</li>
</ol>
</li>
<li>
SecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecond
</li>
<li>
ThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThird
</li>
</ol>
As far as I know, the styling of list numbers with braces is currently not possible. There was a section in the CSS3 spec about custom defining counter styles and using it along with list-style-type but it doesn't seem to be implemented fully yet (atleast not cross-browser) and so your best bet would be to use counters for custom styling the list numbers instead of using the default list style types.
While using counters, we just have to assign one counter for each level, reset/initialize the counter at its corresponding ol tag, increment the counter's value whenever a li is encountered and display the value of the counter before the text using :before pseudo-element. Counter values are displayed using the content property of pseudo-elements and hence the braces can easily be added (it is just like doing string concatenation).
For the (aa), (bb) styles, there is defined counter-style-type and like varun aaruru had mentioned in his comment, there is no pre-defined counter/list style for this and such a value comes only after alphabet z is reached. In default ol styling this could be done giving a start value but it still does not produce the brackets and so we again have to use counters. In counters, we can achieve this by resetting the counter's initial value itself to 26 (z is the 26th alphabet).
The below snippet produces the output that you are looking for.
p.p1 {
text-indent: 0cm;
margin-left: 36;
word-break: break-all;
}
li {
list-style-position: inside;
margin-top: 10pt;
word-break: break-all;
}
li::before {
content: "";
width: 13pt;
display: inline-block;
}
.ol1 {
padding-left: 2pt;
}
.pNote {
text-indent: 0cm;
margin: 0cm 0cm 10pt;
}
/* initialize counters */
ol.a {
counter-reset: list-item-level2;
}
ol.i {
counter-reset: list-item-level3;
}
ol.aa {
counter-reset: list-item-level4 26;
}
/* nullify default list styling */
ol.a li,
ol.i li,
ol.aa li {
list-style-type: none;
}
/* reset the word break for pseudo elements */
ol.a li:before,
ol.i li:before,
ol.aa li:before {
word-break: normal;
}
/* increment the counters */
ol.a li {
counter-increment: list-item-level2;
}
ol.i li {
counter-increment: list-item-level3;
}
ol.aa li {
counter-increment: list-item-level4;
}
/* display the counter values */
ol.a li:before {
content: '('counter(list-item-level2, lower-latin)')';
margin-right: 16px;
}
ol.i li:before {
content: '('counter(list-item-level3, lower-roman)')';
margin-right: 16px;
}
ol.aa li:before {
content: '('counter(list-item-level4, lower-latin)')';
margin-right: 28px;
}
<ol class="ol1">
<li>FirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirstFirst
<ol class="a">
<li>Bullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-aBullet-a
<ol class='i'>
<li>Bullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-iBullet-i
</li>
<ol class="aa">
<li>Bullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aaBullet-aa
</li>
<li>Bullet-abBullet-abBullet-abBullet-abBullet-abBullet-abBullet-abBullet-abBullet-abBullet-abBullet-abBullet-abBullet-abBullet-abBullet-abBullet-abBullet-abBullet-abBullet-abBullet-abBullet-abBullet-abBullet-abBullet-abBullet-abBullet-abBullet-abBullet-abBullet-ab
</li>
</ol>
<li>
Bullet-iiBullet-iiBullet-iiBullet-iiBullet-iiBullet-iiBullet-iiBullet-iiBullet-iiBullet-iiBullet-iiBullet-iiBullet-iiBullet-iiBullet-iiBullet-iiBullet-iiBullet-iiBullet-iiBullet-iiBullet-iiBullet-iiBullet-iiBullet-iiBullet-iiBullet-iiBullet-iiBullet-iiBullet-iiBullet-iiBullet-iiBullet-ii
</li>
</ol>
</li>
<li>
Bullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-bBullet-b
</li>
</ol>
</li>
<li>
SecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecondSecond
</li>
<li>
ThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThirdThird
</li>
</ol>

Why does the list style disappear when display: block is added to a list item in a list (<ul> or <ol>)?

This seems to valid for display: inline; and display: inline-block; too.
This is what I mean:
ul li {
display: block;
/* Or display: inline; */
/* Or display: inline-block; */
}
<ul>
<li>list item1</li>
<li>list item3</li>
<li>list item3</li>
</ul>
And with list style I mean the actual "bullets" or "numbers" (when <ol> is used)
That's because normally, display is set to list-item for <li> elements. See the W3C CSS3 specification: http://www.w3.org/TR/css3-lists/#declaring-a-list-item.
To declare a list item, the ‘display’ property should be set to ‘list-item’.
Note that you can give arbitrary HTML elements the same behaviour; set display: list-item on a <div> for example.
An updated solution is to make use of :before and content.
See this JSfiddle for a working example. http://jsfiddle.net/t72h3/
ul li {
display: inline-block;
}
ul li:before {
content: "• ";
}
<ul>
<li>list item1</li>
<li>list item3</li>
<li>list item3</li>
</ul>
A way to get the effect would be:
<ol>
<li>
desc
</li>
</ol>
CSS:
li {
list-style-position: inside;
display: inline-block; /* or block */
}
li a {
display: list-item;
padding: 10px 20px;
}
Martin's answer is true but doesn't provide a solution and Pappy's is only relevant if you want bullets or easily have access to the what the li's identifier will be. In my case, I need to have an ol with upper-alpha so that's not possible.
The shortest way around this for us was to put a an inline (inline, inline-block, inline-flex) property as well as vertical-align: top on the immediate child of the li:
ol {
list-style: upper-alpha;
> li {
display: block;
}
}
.list-item-content {
display: inline-block; // any inline property will work
vertical-align: top;
}
<ol>
<li>
<div class="list-item-content">Some text</div>
</li>
</ol>
Solution for ul
ul {
list-style: none;
display: block;
padding: 0;
}
ul li::before {
content: "• ";
}
<ul>
<li>list item1</li>
<li>list item3</li>
<li>list item3</li>
</ul>
Solution for ol using counter-increment
ol {
list-style: none;
display: block;
padding: 0;
counter-reset: my-counter;
}
ol li {
counter-increment: my-counter;
}
ol li::before {
content: counter(my-counter) ". ";
}
<ol>
<li>list item1</li>
<li>list item3</li>
<li>list item3</li>
</ol>
Use the CSS property "float:left" for Li(s) to display a list horizontally.
no need to assign "display:block" property.
you can give margin-left or right property to set spaces between text and style shape.
li{
float:left;
margin-right:20px;
}
<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>

Can ordered list produce result that looks like 1.1, 1.2, 1.3 (instead of just 1, 2, 3, ...) with css?

Can an ordered list produce results that looks like 1.1, 1.2, 1.3 (instead of just 1, 2, 3, ...) with CSS? So far, using list-style-type:decimal has produced only 1, 2, 3, not 1.1, 1.2., 1.3.
You can use counters to do so:
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 }
Example
ol { counter-reset: item }
li{ display: block }
li:before { content: counters(item, ".") " "; counter-increment: item }
<ol>
<li>li element
<ol>
<li>sub li element</li>
<li>sub li element</li>
<li>sub li element</li>
</ol>
</li>
<li>li element</li>
<li>li element
<ol>
<li>sub li element</li>
<li>sub li element</li>
<li>sub li element</li>
</ol>
</li>
</ol>
See Nested counters and scope for more information.
None of solutions on this page works correctly and universally for all levels and long (wrapped) paragraphs. It’s really tricky to achieve a consistent indentation due to variable size of marker (1., 1.2, 1.10, 1.10.5, …); it can’t be just “faked,” not even with a precomputed margin/padding for each possible indentation level.
I finally figured out a solution that actually works and doesn’t need any JavaScript.
It’s tested on Firefox 32, Chromium 37, IE 9 and Android Browser. Doesn't work on IE 7 and previous.
CSS:
ol {
list-style-type: none;
counter-reset: item;
margin: 0;
padding: 0;
}
ol > li {
display: table;
counter-increment: item;
margin-bottom: 0.6em;
}
ol > li:before {
content: counters(item, ".") ". ";
display: table-cell;
padding-right: 0.6em;
}
li ol > li {
margin: 0;
}
li ol > li:before {
content: counters(item, ".") " ";
}
Example:
Try it on JSFiddle, fork it on Gist.
The chosen answer is a great start, but it essentially forces list-style-position: inside; styling on the list items, making wrapped text hard to read. Here's a simple workaround that also gives control over the margin between the number and text, and right-aligns the number as per the default behaviour.
ol {
counter-reset: item;
}
ol li {
display: block;
position: relative;
}
ol li:before {
content: counters(item, ".")".";
counter-increment: item;
position: absolute;
margin-right: 100%;
right: 10px; /* space between number and text */
}
JSFiddle: http://jsfiddle.net/3J4Bu/
The solutions posted here did not work well for me, so I did a mixture of the ones of this question and the following question: Is it possible to create multi-level ordered list in HTML?
/* Numbered lists like 1, 1.1, 2.2.1... */
ol li {display:block;} /* hide original list counter */
ol > li:first-child {counter-reset: item;} /* reset counter */
ol > li {counter-increment: item; position: relative;} /* increment counter */
ol > li:before {content:counters(item, ".") ". "; position: absolute; margin-right: 100%; right: 10px;} /* print counter */
Result:
Note: the screenshot, if you wish to see the source code or whatever is from this post: http://estiloasertivo.blogspot.com.es/2014/08/introduccion-running-lean-y-lean.html
Note: Use CSS counters to create nested numbering in a modern browser. See the accepted answer. The following is for historical interest only.
If the browser supports content and counter,
.foo {
counter-reset: foo;
}
.foo li {
list-style-type: none;
}
.foo li::before {
counter-increment: foo;
content: "1." counter(foo) " ";
}
<ol class="foo">
<li>uno</li>
<li>dos</li>
<li>tres</li>
<li>cuatro</li>
</ol>
In the near future you may be able to use the ::marker psuedo-element to achieve the same result as other solutions in just one line of code.
Remember to check the Browser Compatibility Table as this is still an experimental technology.
At the moment of writing only Firefox and Firefox for Android, starting from version 68, support this.
Here is a snippet that will render correctly if tried in a compatible browser:
::marker { content: counters(list-item,'.') ':' }
li { padding-left: 0.5em }
<ol>
<li>li element
<ol>
<li>sub li element</li>
<li>sub li element</li>
<li>sub li element</li>
</ol>
</li>
<li>li element</li>
<li>li element
<ol>
<li>sub li element</li>
<li>sub li element</li>
<li>sub li element</li>
</ol>
</li>
</ol>
You may also want to check out this great article by smashingmagazine on the topic.
The following worked for me:
ol {
list-style-type: none;
counter-reset: item;
margin: 0;
padding: 0;
}
ol > li {
display: table;
counter-increment: item;
margin-bottom: 0.6em;
}
ol > li:before {
content: counters(item, ".") ") ";
display: table-cell;
padding-right: 0.6em;
}
li ol > li {
margin: 0;
}
li ol > li:before {
content: counters(item, ".") ") ";
}
Look at: http://jsfiddle.net/rLebz84u/2/
or this one http://jsfiddle.net/rLebz84u/3/
with more and justified text
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="author" content="Sandro Alvares - KingRider">
</head>
<body>
<style type="text/css">
li.title {
font-size: 20px;
font-weight: lighter;
padding: 15px;
counter-increment: ordem;
}
.foo {
counter-reset: foo;
padding-left: 15px;
}
.foo li {
list-style-type: none;
}
.foo li:before {
counter-increment: foo;
content: counter(ordem) "." counter(foo) " ";
}
</style>
<ol>
<li class="title">TITLE ONE</li>
<ol class="foo">
<li>text 1 one</li>
<li>text 1 two</li>
<li>text 1 three</li>
<li>text 1 four</li>
</ol>
<li class="title">TITLE TWO</li>
<ol class="foo">
<li>text 2 one</li>
<li>text 2 two</li>
<li>text 2 three</li>
<li>text 2 four</li>
</ol>
<li class="title">TITLE THREE</li>
<ol class="foo">
<li>text 3 one</li>
<li>text 3 two</li>
<li>text 3 three</li>
<li>text 3 four</li>
</ol>
</ol>
</body>
</html>
Result:
http://i.stack.imgur.com/78bN8.jpg
I have some problem when there are two lists and second one is inside DIV
Second list should start at 1. not 2.1
<ol>
<li>lorem</li>
<li>lorem ipsum</li>
</ol>
<div>
<ol>
<li>lorem (should be 1.)</li>
<li>lorem ipsum ( should be 2.)</li>
</ol>
</div>
http://jsfiddle.net/3J4Bu/364/
EDIT:
I solved the problem by this
http://jsfiddle.net/hy5f6161/
this is proper code if you want to first child li resize of other css.
<style>
li.title {
font-size: 20px;
counter-increment: ordem;
color:#0080B0;
}
.my_ol_class {
counter-reset: my_ol_class;
padding-left: 30px !important;
}
.my_ol_class li {
display: block;
position: relative;
}
.my_ol_class li:before {
counter-increment: my_ol_class;
content: counter(ordem) "." counter(my_ol_class) " ";
position: absolute;
margin-right: 100%;
right: 10px; /* space between number and text */
}
li.title ol li{
font-size: 15px;
color:#5E5E5E;
}
</style>
in html file.
<ol>
<li class="title"> <p class="page-header list_title">Acceptance of Terms. </p>
<ol class="my_ol_class">
<li>
<p>
my text 1.
</p>
</li>
<li>
<p>
my text 2.
</p>
</li>
</ol>
</li>
</ol>
I was after adding numbered list to Python Markdown's TOC Extension.
I did something like this:
.toc ul { counter-reset: outItem; list-style: none }
.toc ul > li{ counter-reset: nestedItem }
.toc ul > li:before { content: counters(outItem, ".") ". "; counter-increment: outItem; margin-left: -2em; }
I am not sure it is the correct way, but it worked for me.
I needed to add this to the solution posted in 12 as I was using a list with a mixture of ordered list and unordered lists components. content: no-close-quote seems like an odd thing to add I know, but it works...
ol ul li:before {
content: no-close-quote;
counter-increment: none;
display: list-item;
margin-right: 100%;
position: absolute;
right: 10px;
}