I am trying to write Table of Contents using HTML in a file. The numbering that appears in my Table of Contents is flawed. How can I modify the following CSS and HTML so that the fourth bullet point in my Output is 4 instead of 3.4?
ol {
counter-reset: item;
}
ol li {
line-height: 30px;
}
ol ol li {
line-height: 20px;
}
li {
display: block;
}
li:before {
content: counters(item, ".")" ";
counter-increment: item;
}
<ol>
<li>
lorem ipsum
</li>
<li>
Set
</li>
<li>
Title
</li>
<ol>
<li>
Class
</li>
<li>
Something
</li>
<li>
Action
</li>
</ol>
<li>
Table of References
</li>
</ol>
Output
1. Lorem Ipsum
2. Set
3. Title
3.1. Class
3.2. Something
3.3. Action
3.4. Table of References
As the comment said (#Jon P): Your HTML is invalid. You can not have ol as a direct descendant of ol it needs to be wrapped in a li.
To nesting lists properly, just move the sub ol inside the 3rd li, check the example below:
REF: https://developer.mozilla.org/en/docs/Web/HTML/Element/ol
ol {
counter-reset: item;
}
ol li {
line-height: 30px;
}
ol ol li {
line-height: 20px;
}
li {
display: block;
}
li:before {
content: counters(item, ".")" ";
counter-increment: item;
}
<ol>
<li>
lorem ipsum
</li>
<li>
Set
</li>
<li>
Title
<ol>
<li>
Class
</li>
<li>
Something
</li>
<li>
Action
</li>
</ol>
</li>
<li>
Table of References
</li>
</ol>
You're closing your LI tag too early after Title - move it below the OL section, like this:
<ol>
<li>
lorem ipsum
</li>
<li>
Set
</li>
<li>
Title
<ol>
<li>
Class
</li>
<li>
Something
</li>
<li>
Action
</li>
</ol>
</li>
<li>
Table of References
</li>
</ol>
Related
I am going through this link to understand more on counters and how nested counter work,
I have the css and html as following
<style>
ol {
counter-reset: my-counter 0;
list-style-type: none;
}
li::before {
content: counters(my-counter, '.');
counter-increment: my-counter;
}
</style>
With the html as
<ol>
<li> First
<ol>
<li> Eleven </li>
<li> Twelve </li>
</ol>
</li>
<li> Second
<ol>
<li> Twenty-one </li>
<li> Twenty-two </li>
</ol>
</li>
</ol>
Here i am getting the content as expected, like 1 and 1.1, however changing the before to marker pseudo element i.e li::marker gives a value like 0 and 0.0.
Although when i use only this css, the output is as expected
li::marker {content: counters(list-item, '.') ' ';}
I couldn't get why the before and marker pseudo elements are generating different output for this list.
The issue is related to the allowed properties within ::marker. content is allowed but not counter-increment so it's working but without incrementing the counter.
If you move the incrementation to li it works:
ol {
counter-reset: my-counter 0;
list-style-type: none;
}
li::marker {
content: counters(my-counter, '.');
}
li {
counter-increment: my-counter;
}
<ol>
<li> First
<ol>
<li> Eleven </li>
<li> Twelve </li>
</ol>
</li>
<li> Second
<ol>
<li> Twenty-one </li>
<li> Twenty-two </li>
</ol>
</li>
</ol>
More detail about the allowed properties can be found in the Specification: https://www.w3.org/TR/css-lists-3/#marker-properties
I want to make an unordered list the has an ordered second level that continues counting it's points. I know I can do it with <ol start="Previous number+1"> but is it possible to continue list automatically? Below is an example as well as example in the picture.
First
a. first
b. second
Second
c. third
This is how I've done it:
<ul>
<li>ASV:<br/><ol type="I">
<li>HP</li><li>Dell</li><li>Apple</li><li>Google</li><li>Microsoft</li><li>EVGA Corporation</li><li>Maingear</li><li>Origin PC</li><li>Velocity Micro</li><li>Vizio</li></ol>
</li>
<li>Ķīna:<br/><ol type="I" start="11">
<li>Lenovo</li><li>Huawei</li><li>Founder</li><li>Hasee</li><li>Lemote</li></ol>
</li>
<li>Japāna:<br/><ol type="I" start="16">
<li>Panasonic</li><li>Sharp</li><li>Toshiba</li><li>VAIO</li>
</ol></li>
<li>Taivāna:<br/><ol type="I" start="20">
<li>Acer</li><li>Asus</li><li>Clevo</li><li>Gigabyte Technology</li><li>Via</li>
</ol></li>
I'm just a beginner so I'm sorry if the format isn't the greatest.
This is the example
you can do that with css Counter :
https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Lists_and_Counters/Using_CSS_counters
https://developer.mozilla.org/en-US/docs/Web/CSS/counters
sample code:
ul#my-list {
list-style: none;
counter-reset: nRef;
counter-reset: aRef;
}
ul#my-list>li { counter-increment: nRef; }
ul#my-list>li:before { content: counter(nRef) '. '; }
ul#my-list>li>ul { list-style: none; }
ul#my-list>li>ul>li { counter-increment: aRef; }
ul#my-list>li>ul>li:before { content: counter(aRef, lower-alpha) '. '; }
<ul id="my-list">
<li>ASV:
<ul>
<li>HP</li><li>Dell</li><li>Apple</li><li>Google</li>
<li>Microsoft</li><li>EVGA Corporation</li><li>Maingear</li>
<li>Origin PC</li><li>Velocity Micro</li><li>Vizio</li>
</ul>
</li>
<li>Ķīna:
<ul>
<li>Lenovo</li><li>Huawei</li><li>Founder</li>
<li>Hasee</li><li>Lemote</li>
</ul>
</li>
<li>Japāna:
<ul>
<li>Panasonic</li><li>Sharp</li><li>Toshiba</li><li>VAIO</li>
</ul>
</li>
<li>Taivāna:
<ul>
<li>Acer</li><li>Asus</li><li>Clevo</li>
<li>Gigabyte Technology</li><li>Via</li>
</ul>
</li>
</ul>
I have nested lists of which I can't change the structure of. The first li element must not be included in the numbering, however, its children must ALL be numbered. Here is the JsFiddle.
ol li ol {
counter-reset: section;
list-style-type: none;
}
ol li ol li::before {
counter-increment: section;
content: counters(section, ".") " ";
}
<ol id="root">
<li>List item two with subitems (this should not be numbered):
<ol id="toc0">
<li>Subitem 1 (This should be numbered 1)</li>
<li>Subitem 2 (This should be 2)</li>
<ol>
<li> subitem (this should be 2.1)</li>
<li> subitem (this should be 2.2)</li>
<ol>
<li> subitem (This should be 2.2.1)</li>
<li> subitem (This should be 2.2.2)</li>
</ol>
</ol>
<li>Subitem 3 (This should be 3)</li>
<li>Subitem 4 (This should be 4)</li>
</ol>
</li>
</ol>
You have invalid markup, ol cannot be a direct child of another ol. You must update the HTML to fix it, your existing CSS works fine with a little edit.
ol {
list-style: none;
}
ol li ol {
counter-reset: section;
}
ol li ol li::before {
counter-increment: section;
content: counters(section, ".") " ";
}
<ol id="root">
<li>List item two with subitems (this should not be numbered):
<ol id="toc0">
<li>Subitem 1 (This should be numbered 1)</li>
<li>
Subitem 2 (This should be 2)
<ol>
<li>subitem (this should be 2.1)</li>
<li>
subitem (this should be 2.2)
<ol>
<li> subitem (This should be 2.2.1)</li>
<li> subitem (This should be 2.2.2)</li>
</ol>
</li>
</ol>
</li>
<li>Subitem 3 (This should be 3)</li>
<li>Subitem 4 (This should be 4)</li>
</ol>
</li>
</ol>
is it possible to have my ordered list in the following format?
heading
1.1. text...
1.2. text
1.2.1 text
Another heading
1.3. text
1.3.1. text
1.3.2. text
1.4. text
Is that possible?
Thank you
ol { counter-reset: item }
li { display: block }
li:before { content: counters(item, ".") " "; counter-increment: item }
<ol>
<li> Cat</li>
<li>Bat</li>
<li>Mat
<ol>
<li>Red Mat</li>
<li>Green Mat</li>
</ol>
</li>
<li>Pat</li>
</ol>
.contract ol {
counter-reset: item
}
.contract li.paragraph {
counter-increment: item;
}
.contract li li.paragraph:before {
content: counters(item, ".")" ";
}
.contract li {
list-style-type: none;
}
.contract ol {
padding-left: 0;
}
<section class="contract">
<ol>
<li class="paragraph">
<ol>
<li>
<h2>Heading</h2>
</li>
<li class="paragraph">text</li>
<li class="paragraph">text
<ol>
<li class="paragraph">text</li>
</ol>
</li>
<li>
<h2>Another heading</h2>
</li>
<li class="paragraph">text
<ol>
<li class="paragraph">text</li>
<li class="paragraph">text</li>
</ol>
</li>
<li class="paragraph">text</li>
</ol>
</li>
</ol>
</section>
I have a three level ordered list in html that I would like to give a style as following:
1. Item 1
1.1 Item 2
1.1.1 Item 3
An example of the html is in the next plunker:
http://plnkr.co/edit/DqhZ5pJILTUHGSNaA1vm?p=preview
I have done a style recommended in the internet with css like
ol { counter-reset: item }
li:before { content: counters(item, "."); counter-increment: item }
but it doesn't seem working.
Please, any comment related would be a great help.
Use the following code:
html:
<ol>
<li> Should be Item 1
<ol>
<li> Should be Item 1.1</li>
<li> Should be Item 1.2</li>
<li> Should be Item 1.3
<ol>
<li> Should be Item 1.3.1
</ol>
<li>Should be Item 1.4</li>
</ol>
</li>
<li> Should be Item 2</li>
</ol>
css:
ol { counter-reset: item }
ol li { display: block }
ol li:before { content: counters(item, ".") ". "; counter-increment: item }
your css code is almost fine, see http://plnkr.co/edit/wmGhz7V6CKqZ7MmHIoDF?p=preview
you have an extra </li><li> after level 1, so your markup becomes
<ol>
<li> Should be Item 1
<ol>
<li> Should be Item 1.1</li>
<li> Should be Item 1.2</li>
<li> Should be Item 1.3
<ol>
<li> Should be Item 1.3.1</li>
</ol>
</li>
<li>Should be Item 1.4</li>
</ol>
</li>
<li> Should be Item 2</li>
</ol>
and in your css I've removed the base list style for ol with list-style: none;