Home >Web Front-end >CSS Tutorial >How Can I Elegantly Colorize Bullets in HTML Lists Using Only CSS?
Bullet Colorization in HTML Lists with CSS: An Elegant Approach
Many developers face the challenge of customizing bullet colors in unordered lists (UL) and list items (LI) using HTML and CSS, without resorting to image sprites or span tags. This article explores a comprehensive solution that allows you to achieve this goal with ease.
Consider a scenario where you have defined the bullet shape as a square, but changing the color of the LI items changes everything to red. To isolate the bullet colorization, you need an elegant solution that leverages CSS's capabilities.
The most widely used method involves the following steps:
Here's an example code snippet:
ul { list-style: none; padding: 0; margin: 0; } li { padding-left: 1em; text-indent: -.7em; } li::before { content: "• "; color: red; /* or any preferred color */ }
<ul> <li>Foo</li> <li>Bar</li> <li>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</li> </ul>
This approach provides a flexible and efficient way to customize bullet colors in HTML lists, enabling you to achieve desired visual effects without the use of images or additional HTML elements.
The above is the detailed content of How Can I Elegantly Colorize Bullets in HTML Lists Using Only CSS?. For more information, please follow other related articles on the PHP Chinese website!