Styling indent with HTML or CSS like in Ms Word - css

I need a help to get a., b. style inner indent instead of 2.2.1., 2.2.2.. Found the original CSS code from HTML ordered list indent to keep original numbering
My code:
<style>
ol { counter-reset: item }
li { display: block }
li:before { content: counters(item, ".") ". "; counter-increment: item }
</style>
<ol>
<li>One</li>
<li>
Two
<ol>
<li>Two one</li>
<li>
Two two
<ol type="a">
<li>Two two a</li>
<li>Two two b</li>
</ol>
</li>
<li>Two three</li>
</ol>
</li>
<li>Three</li>
</ol>
What I'm getting:
1. One
2. Two
2.1. Two one
2.2. Two two
2.2.1. Two two a
2.2.2. Two two b
2.3. Two three
3. Three
What I need:
1. One
2. Two
2.1. Two one
2.2. Two two
a. Two two a
b. Two two b
2.3. Two three
3. Three

Since you don't need to prepend the inner lists with the section numbering, you can add an additional rule using counter to get the letters:
ol {
counter-reset: item;
}
li {
list-style: none;
}
li:before {
content: counters(item, ".")". ";
counter-increment: item
}
ol ol ol li:before {
content: counter(item, lower-alpha)". ";
}
Details: http://jsfiddle.net/kmAJ6/3/. Should work with your existing HTML.

Your type attribute has no effect because your css replaces the default numbering. One way around this would be to update your css rules to only target the first 2 levels and let the 3rd level use the default numbering. This will then let your type attribute take effect.
http://jsfiddle.net/TbjcV/
.level1,
.level2{
counter-reset: item
}
.level1 > li,
.level2 > li{
display: block
}
.level1 > li:before,
.level2 > li:before{
content: counters(item, ".") ". ";
counter-increment: item
}
<ol class="level1">
<li>One</li>
<li>
Two
<ol class="level2">
<li>Two one</li>
<li>
Two two
<ol type="a" class="level3">
<li type="a">Two two a</li>
<li>Two two b</li>
</ol>
</li>
<li>Two three</li>
</ol>
</li>
<li>Three</li>
</ol>

I got this:
<style>
ol.cnt { counter-reset: item }
ol.cnt > li { display: block }
ol.cnt > li:before { content: counters(item, ".") ". "; counter-increment: item }
</style>
html:
<ol class="cnt">
<li>One</li>
<li>
Two
<ol class="cnt">
<li>Two one</li>
<li>
Two two
<ol type="a">
<li>Two two a</li>
<li>Two two b</li>
</ol>
</li>
<li>Two three</li>
</ol>
</li>
<li>Three</li>
</ol>
a bit messy, but seems to work.

Related

How do I get css counters to continue [duplicate]

This question already has answers here:
Three level decimal ordered list CSS
(2 answers)
Closed 4 years ago.
The counter is not continuing numbering, I would expect the second li (DEFINITIONS) to have number 2 but it continues the numbering of the nested ol so it has the number 1.2 instead of 2:
list--sub-decimal {
counter-reset: decimal;
> li:before {
counter-increment: decimal;
content: counters(decimal, ".", decimal) " ";
}
}
<ol class="list--none">
<li>
<ol class="list--sub-decimal">
<li class="subItem"><strong>DEFINITIONS</strong></li>
<ol class="list--sub-decimal">
<li class="subItem"><strong>"Agreement"</strong> blaa</li>
</ol>
<li class="subItem"><strong>DEFINITIONS</strong></li>
</ol>
</li>
</ol>
Thanks!!
You need to start by writing valid HTML for stuff like this to work.
Your second <ol class="list--sub-decimal"> is not properly wrapped inside a li, but is a child of the ol above it - which is not allowed.
Once you fix that, it works:
.list--sub-decimal {
counter-reset: decimal;
}
.list--sub-decimal > li:before {
counter-increment: decimal;
content: counters(decimal, ".", decimal) " ";
}
<ol class="list--none">
<li>
<ol class="list--sub-decimal">
<li class="subItem"><strong>DEFINITIONS</strong>
<ol class="list--sub-decimal">
<li class="subItem"><strong>"Agreement"</strong> blaa</li>
</ol>
</li>
<li class="subItem"><strong>DEFINITIONS</strong></li>
</ol>
</li>
</ol>

Nested list css styling

I want to create css to generate the following nested list.
1. item1
subitem
subitem
2. item2
subitem
subitem
What I want is to modify the numbers (either bold or red). I searched in the internet but what I found was css for an ordered list. When I create a nested list with that css, what I obtain is extra numbers in place of the bullets. Can someone help?
You can use CSS counter only on li's that are direct children of ol with this HTML structure and then change color and font-weight.
ol {
list-style: none;
counter-reset: ol-counter;
}
ol > li:before {
counter-increment: ol-counter;
content: counter(ol-counter) ". ";
color: red;
font-weight: bold;
}
<ol>
<li>item1
<ul>
<li>sub item</li>
<li>sub item</li>
</ul>
</li>
<li>item2
<ul>
<li>sub item</li>
<li>sub item</li>
</ul>
</li>
</ol>

Style subitems in ordered list numbers with CSS

I will use an other design for an ordered list. So I found a nice solution here on SO.
body { counter-reset: item; }
ol.numbered_style li:before
{
counter-increment:item;
margin-bottom:5px;
margin-right:10px;
content:counter(item);
background:gold;
border-radius:100%;
color:white;
width:1.2em;
text-align:center;
display:inline-block;
}
ol.none, ul.none,ol.numbered_style { list-style: none; }
<ol class="numbered_style">
<li>First</li>
<li>Second</li>
<li>Third
<ol class="none">
<li>Subitem</li>
</ol>
</li>
<li>Fourth
<ul class="none">
<li>Other Subitem</li>
</ul>
</li>
</ol>
How is it possible not to use this style for sub-items in a list?
Why isn't the conditions for my class called none not working?
Also what do I have to do, if I want a second ordered list with the same class. It should begin with 1. <ol class="numbered_style" start="1"> didn't helped.
Is it possible to start a ordered list with a specify number like 2 or 1.1? For a normal ol I could use start="number", but I think it is disabled because of ol.numbered_style { list-style: none; }.
Adding as an answer since there are more than one part to the question:
How is it possible not to use this style for subitems in a list?
Use the children selector (>) to select only the li that are directly present under the parent ol tag instead of selecting all li elements that are at any level under the parent ol tag. The list-style setting has no effect here because the numbering here is generated and added using counters.
But what do I have to do, if I want a second ordered list with the same class. It should began with 1.
Add a counter-reset with the ol.numbered_style selector so that the number is reset everytime that element is encountered. This will make it restart at 1.
I don't need this now, but is there also a solution to start this ordered list with a specify number like 2 or 1.1?
Yes, starting it at 2 is possible. In the counter-reset property we can also provide the initial value of the counter (as the second in a list of space separated values). Refer below snippet for a demo.
body, ol.numbered_style {
counter-reset: item;
}
ol.numbered_style.starts_at_2 {
counter-reset: item 1; /* the second is the start value, default is 0 */
}
ol.numbered_style > li:before {
counter-increment: item;
margin-bottom: 5px;
margin-right: 10px;
content: counter(item);
background: gold;
border-radius: 100%;
color: white;
width: 1.2em;
text-align: center;
display: inline-block;
}
ol.none, ul.none, ol.numbered_style {
list-style: none;
}
<ol class="numbered_style">
<li>First</li>
<li>Second</li>
<li>Third
<ol class="none">
<li>Subitem</li>
</ol>
</li>
<li>Fourth
<ul class="none">
<li>Other Subitem</li>
</ul>
</li>
</ol>
<ol class="numbered_style">
<li>First</li>
<li>Second</li>
<li>Third
<ol class="none">
<li>Subitem</li>
</ol>
</li>
<li>Fourth
<ul class="none">
<li>Other Subitem</li>
</ul>
</li>
</ol>
<ol class="numbered_style starts_at_2">
<li>First</li>
<li>Second</li>
<li>Third
<ol class="none">
<li>Subitem</li>
</ol>
</li>
<li>Fourth
<ul class="none">
<li>Other Subitem</li>
</ul>
</li>
</ol>
Making it start at 1.1 is a bit more tricky as we have to add one counter at ol level and another at li level. Below is a sample demo.
body{
counter-reset: ol ;
}
ol.numbered_style{
counter-reset: li;
counter-increment: ol;
}
ol.numbered_style > li:before {
counter-increment: li;
content: counter(ol) "." counter(li);
margin-bottom: 5px;
margin-right: 10px;
background: gold;
border-radius: 100%;
color: white;
width: 2em;
text-align: center;
line-height: 2em;
display: inline-block;
}
ol.none, ul.none, ol.numbered_style {
list-style: none;
}
<ol class="numbered_style">
<li>First</li>
<li>Second</li>
<li>Third
<ol class="none">
<li>Subitem</li>
</ol>
</li>
<li>Fourth
<ul class="none">
<li>Other Subitem</li>
</ul>
</li>
</ol>

How strike through a bullet in list

We have eBook, in that one of the list has strike through the text as well as the bullet. i can able to strike the text using (text-decoration: line-through;). But i can strike through the bullet in the list, please help me to get a solution?
Here is one way to implement
with Order list
HTML :
<body>
This fiddle is used to demonstrate the list styling with CSS
<ol>
<li> Item 1 </li>
<li> Item 2 </li>
<li> Item 3 </li>
<li> Item 4 </li>
</ol>
</body>
and CSS :
ol li
{
list-style-type: none;
counter-increment: item;
text-decoration:line-through;
}
ol li::before
{
content:counter(item) ".";
text-decoration:line-through;
}
With unordered list, it is a little bit more complicated
HTML:
<body>
This fiddle is used to demonstrate the unordered list styling with CSS
<ul>
<li>item 1</li>
<li>item 2</li>
<li>item 3</li>
<li>item 4</li>
</ul>
</body>
and CSS:
ul{
float:left;
}
li {
list-style: circle;
list-style-position: inside;
margin-top:8px;
}
li:after{
border-top:1px solid red;
display:block;
content:"";
margin-top:-8px;
}

zurb foundation targeting nested ol ul list

I'm trying to have the 2nd part of the nested ol have alphabet list items but it's all appearing as numbers. How do I change it to have a) and b) in the second nested part ?
<p>This is some texts:<br>
<ol>
<ol>
<li class=first list item.</li>
<li class="list-numbers">second list item</li>
</ul>
Some text
<ol class="list-alphabet">
<li class="list-alphabet">first list item second part.</li>
<li class="list-alphabet">second list item second part</li>
</ol>
</ol>
</div>
ol.alphabet li {
list-style: lower-alpha;
}
.alphabet ol li {
list-style: lower-alpha;
}
ol-.alphabet li {
list-style: lower-alpha;
}
ol li ol li.alphabet {
list-style: lower-alpha;
}
ol li ol li. {
list-style: lower-alpha;
}
See fiddle http://jsfiddle.net/setbon/gGEKH/
Looks like you mixed up your CSS 'list-alphabet / alphabet' names.
Updated code
<p>This is some texts:</p>
<br>
<ol>
<ol>
<li>first list item.</li>
<li>second list item</li>Some text
<ol class="alphabet">
<li>first list item second part.</li>
<li>second list item second part</li>
</ol>
</ol>
</ol>
CSS
ol.alphabet li {
list-style: lower-alpha;
}

Resources