Imagine a simple unsorted list with some <li>
items. Now, I have defined the bullets to be square shaped via list-style:square;
However, if I set the color of the <li>
items with color: #F00;
then everything becomes red!
While I only want to set the color of the square bullets. Is there an elegant way to define the color of the bullets in CSS...
HTML
<ul> <li>Item 1</li> <li>Item 2</li> <li>Item 3</li> <ul>
CSS
li{ list-style:square; }
However, if you do change the markup, one solution is to wrap the text of each list item in an extra element, e.g., a SPAN. If the list item looks like this: <li><span>First item</span></li> then you can make the bullet red and the text black with `li {color: red}' and `li span {color: black}'.
To change the bullet to an image, we will add two new CSS classes one for the <ul> element the other one for the <li> element. For the list class, we will set the padding and the margin to "0" and set the list-style-type to none.
browsing sometime ago, found this site, have you tried this alternative?
li{ list-style-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAAECAYAAACp8Z5+AAAAE0lEQVQIW2NkYGD4D8RwwEi6AACaVAQBULo4sgAAAABJRU5ErkJggg=="); }
sounds hard, but you can make your own png image/pattern here, then copy/paste your code and customize your bullets =) stills elegant?
EDIT:
following the idea of @lea-verou on the other answer and applying this philosophy of outside sources enhancement I've come to this other solution:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
i.e.: fa-angle-right []
and use the last part of f... followed by a number like this, with the font-family
too:
li:before { content: "\f105"; font-family: FontAwesome; color: red; /* or whatever color you prefer */ margin-right: 4px; }
and that's it! now you have custom bullet tips too =)
fiddle
The most common way to do this is something along these lines:
ul { list-style: none; padding: 0; margin: 0; } li { padding-left: 1em; text-indent: -.7em; } li::before { content: "• "; color: red; /* or whatever color you prefer */ }
<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>
JSFiddle: http://jsfiddle.net/leaverou/ytH5P/
Will work in all browsers, including IE from version 8 and up.
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