Reputation: 13914
I have the following ordered list:
<ol>
<li>
<span>Title</span>
<ol>
<li>Info</li>
<li>Info</li>
</ol>
</li>
</ol>
With CSS I need to apply styling to only the parent li
, so only the 1. Title
and not the child ol
. How do I do this?
I have tried the following:
body > ol > li {
/* Styling here */
}
and
body > ol > li > span {
/* Styling here */
}
But neither gives the desired effect.
body > ol > li {
font-weight: bold;
font-size: 20px;
}
/* Additional styling */
ol { counter-reset: item; }
li { display: block }
li:before { content: counters(item, ".") ". "; counter-increment: item }
<body>
<ol>
<li>
<span>Title</span>
<ol>
<li>Info</li>
<li>Info</li>
</ol>
</li>
</ol>
</body>
Upvotes: 0
Views: 49
Reputation: 5494
Even though Blaze Sahlzen has the best answer, here's another possible solution:
https://jsfiddle.net/6mhajeLf/6/
Done by adding a class to the items that don't need to be bold and using !important
. A little bit dirty, but it works.
.not-bold {
font-weight:300 !important;
}
Upvotes: 0
Reputation: 2666
I added this CSS to your code:
span + ol {
font-weight: initial;
font-size: initial;
}
body > ol > li {
font-weight: bold;
font-size: 20px;
}
span + ol {
font-weight: initial;
font-size: initial;
}
/* Additional styling */
ol { counter-reset: item; }
li { display: block }
li:before { content: counters(item, ".") ". "; counter-increment: item }
<body>
<ol>
<li>
<span>Title</span>
<ol>
<li>Info</li>
<li>Info</li>
</ol>
</li>
</ol>
</body>
Upvotes: 3
Reputation: 1453
If I correctly understand what you are trying to achieve, you need to declare
body > ol > li:first-child { color: #FFF; }
body > ol > li:first-child > ol { color:#000; }
See example: https://jsfiddle.net/6mhajeLf/4/
Upvotes: 0
Reputation: 13914
I suppose the only solution would be to reset the styling manually on the child ol
like this:
ol ol {
/* Reset styling */
}
Upvotes: 0