I have an ordered list
<ol>
<li class="odd">Lorem ipsum dolor sit amet, consectetur ...</li>
<li class="even">Some more text</li>
</ol>
To look something like this:
I want the list to have list-position: outside so the numbers overhang (as they do on this page) but have the background of each list item (which alternate) cover the numbers as well.
1) Check the scale you want to add color to in the Apply to section. If you check Row of data range in the Apply to section, you need to select the row range. 2) Add colors to the items of drop-down list one by one. Click at one item in the List Items, then click one color you need to add the color to the selected item.
How to Set Background Color with HTML and CSS Add the style attribute to the <body> element ¶. You can set a background color for an HTML document by adding... Add the CSS background-color property to the <body> element ¶. The background-color property is used to change the... Create a background ...
Click Home > the arrow next to Fill Color, or press Alt+H, H. Under Theme Colors or Standard Colors, pick the color you want. To use a custom color, click More Colors, and then in the Colors dialog box select the color you want. Tip: To apply the most recently selected color, you can just click Fill Color.
To use a different background color for the whole worksheet, click the Select All button. This will hide the gridlines, but you can improve worksheet readability by displaying cell borders around all cells. Click Home > the arrow next to Fill Color, or press Alt+H, H. Under Theme Colors or Standard Colors, pick the color you want.
As the "outside" name suggests, the numbers are placed outside the element so you cannot affect them with li's background color. A workaround for this may be using an additional div inside the li:
<ol>
<li><div>Lorem ipsum dolor sit amet, consectetur ...</div></li>
<li><div>Some more text ...</div></li>
</ol>
Then add the following CSS for the div:
ol li div {
width: 100%;
height: 100%;
background-color: #FFAAAA;
margin-left: -20px;
padding-left: 20px;
}
This will move the div to appear under the number (that's the -20px value) and the text in it back to the right place (that 20px value).
instead of using outside, could you use list-position: inside, set the background, and then use a negative left margin to push it out?
One option to try is text-indent
, e.g.
li {
list-style-position: inside;
text-indent: -1em;
padding: 10px 2em;
background-color: lime;
}
li.odd {
background-color: aqua;
}
I've used a negative text-indent to pull the first line of text out, and then left padding to pull everything back into alignment. You might need to play with the text indent and padding values a bit. I've only tested this with list items with single-digit numbers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With