I'm a newbie at CSS/HTML and I have a website assignment due in an hour's time and I can't seem to get the bullet points on my page to just be white (instead of the default black) without the alignment screwing up and appearing in places I don't want it to be like the navbar
Here's what is looks like normally
default bullet points
and here is the code normally
code for default bullet points
and here's what it looks like when I include this code (in the CSS) that I found on this Stack Overflow (Change bullets color of an HTML list without using span):
li {
list-style: none;
}
li:before {
/* For a round bullet */
content: '\2022';
/* For a square bullet */
/*content:'\25A0';*/
display: block;
position: relative;
max-width: 0;
max-height: 0;
left: -10px;
top: 0;
color: white;
font-size: 20px;
}
broken bullet points after copypasta from stack overflow
The problem with the code you copied and pasted is that it's modifying the position of the bullet with position: relative and the top and left properties. I'd recommend you used this code instead:
li::before {
content: "\2022";
color: white;
font-weight: bold;
display: inline-block;
width: 1em;
margin-left: -1em;
}
Which doesn't modify the position of the bullet.
The code you copy-pasted is doing a lot of things that you probably don't yet understand.
list-style: none removes the default bullets completely.
li:before allows you to pretend there is another element inside the list item, before its content, and lets you style that pseudo-element.
So the code you copied is trying to manually create fake bullets instead of customizing the ones that already exist. This is what I'd call a CSS hack, it's not something you would do unless you're trying to achieve a very specific look that's impossible to get using normal means.
If all you're trying to do is replace the bullet icon, that can be done with the CSS property list-style-type.
I am not a web developer so please bear with me on that.
I have a website (WordPress) that I'm trying to make a small update to before getting professional assistance. I have updated this page https://www.trustserve.net/legal-privacy/ which you will see has bullets and numbers. Originally when I input this text the bullets and numbers were appearing black. I updated the CSS code which I will include below that fixed that issue. The problem however is that my main menu at the top of each page now has a bullet next to it as well.
Main Menu:
I have seen numerous posts regarding bullets and WordPress sites but I can't connect the dots (no pun intended!) between those posts and my issue specifically.
I assume I need to add some HTML for the Main Menu specifically to remove the bullets but I don't know how to do that and this is what I need help with. Any assistance that will help me remove bullets in my main menu without impacting the bullets on the other page is greatly appreciated.
My CSS updates are as follows:
ol {color: white }
ol li::before {
color: white;
}
ul { list-style: none;} /* Remove default bullets */
ul li::before {
content: "\2023"; /* Unicode bullet symbol */
color: white; /* Bullet color */
padding-right: 10px;
}
Address only the lis in the (main) menu by using its ID in the selector and reset the content of the pseudo element you created:
#menu-main-menu li::before {
content: "";
}
...or content: none in that rule. The difference will be the horizontal spacing between the menu items - choose which one you prefer.
try to get rid of this using content: "\2023"; code if you have access to the wordpress css theme, or just override it with your own css file by letting the string empty, as follows
ul li::before {
content: "";
color: white;
font-weight: bold;
padding-right: 10px;
}
That should work, and never underestimate the help of the inspector of your web browser ;)
I would like to use an HTML Symbol (→) as a bullet for my list items. I have tried using an image but it just doesn't look right. I have also looked in to using the :before selector, but HTML code does not seem to work in that instance. Is there a way that I can use HTML code as a bullet point, and if so, how? Thanks in advance.
Quite simple actually.
ul {
position: relative;
list-style: none;
margin-left: 0;
padding-left: 1.2em;
}
ul li:before {
content: "→";
position: absolute;
left: 0;
}
This has already been answered in Custom bullet symbol for <li> elements in <ul> that is a regular character, and not an image, by the way.
Thanks to Jpsy for this code.
How can I change color / size / display-character of <ol> or <ul> list bullets while maintaining separate control over the rest of the list item?
Solution should handle changes to both list types.
p.s. I've seen a few closely related questions on this matter and wanted to give an inclusive solution (two main variations) to the general problem.
Option 1 - <ul> unordered lists: replace original bullet with your own
Upside: requires little change to code.
Downsides: doesn't control individual list items, does not work with ordered lists (see option 2).
Step 1. First get rid of existing list bullets:
ul {
list-style: none;
}
Basic options include (disc, square, circle)
Less Basic - use image: ul { list-style: square inside url("sqpurple.gif"); - try it
Another img example - 16px Spinner bullets (paste in 'try it' code):
list-style: square inside url("http://agroportal.lirmm.fr/assets/spinners/spinner_000000_16px-4f45a5c270658c15e01139159c3bfca130a7db43c921af9fe77dc0cce05132bf.gif");
Step 2. add a replacement before list item information:
ul li:before {
content: "•"; // change what you like
// 'before' does not change li styles
font-size: 150%; // a few options
padding-right: 5px;
color: blue;
}
Note: it might be better to use Unicode "\002022" instead of "•"
Alternatively: use another symbol, webding, icon-font favicon.ico image, etc.
ul li:before {
content: "4"; font-family:"Webdings";
}
Another Example: FontAwesome icon - after you get-started add:
content: "<i class="fa fa-check-circle"></i>" // fontawesome API
Option 2 - <ol> ordered lists: keep original item numbering / lettering but break the list style from <li>'s content style using <div> or <span>
Upsides: works for ordered lists, control each list item individually or collectively.
Downsides: tags for each <li>, less bullet control.
HTML
<ol class="ol--bullet-style">
<li><div class="li--default">Foo</div></li>
<li><div class="li--default">Foo</div></li>
<li><div class="li--default">Foo</div></li>
</ol>
CSS:
.ol--bullet-style {
color: red; // some options
font-size: 150%;
font-decoration: underline;
font-family: Courier New;
}
.li--default {
font-family: Garamond;
font-size: 100%;
}
Or go basic with a div or span tag that does not include a class and use this in your css:
ul li div {
color: blue;
}
NOTE: a <p> tag is not recommended since it comes with its own special defaults.
I'm using the following list:
<ol id="footnotes">
<a name="footnote1"><li></a>This is the first footnote...</li>
<a name="footnote2"><li></a>This is the second footnote...</li>
</ol>
With the following .css:
#footnotes {list-style-type: decimal;
list-style-color: #f90;
}
#footnotes li
{color: #000;
}
#footnotes a li,
#footnotes li a
{color: #f90;
}
The aim is to have the li/footer text itself black (#000), and the number styled to orange (#f90).
I've tried using the list-style-color property but this does nothing except upset the Web developer toolbar (in FF3.0.8/Ubuntu 8.04), Midori similarly doesn't display the number in orange (I thought I'd try it in the Webkit engine, just in case...).
Any ideas?
Edited the HTML (since I remembered that the tag doesn't necessarily need to enclose anything to function as an anchor):
<ol id="footnotes">
<li><a name="footnote1"></a>This is the first footnote...</li>
<li><a name="footnote2"></a>This is the second footnote...</li>
</ol>
In response to those that suggest using a <span> inside the <li>...yeah. That occurred, though I thank you for the suggestions and the time taken, but I was looking (li'l standardista that I am... ;) ) for a more...semantic option.
As it is, I think I'll probably use that approach. Though I accepted a different, Pete Michaud's, answer due to its sheer informative nature. Thanks!
There is a way in CSS3, using the Generated and Replaced Content Module. With this technique you don't have do add any extra mark-up to your HTML. Something like this should do the trick:
ol li {
list-style-type: none;
counter-increment: list;
position: relative;
}
ol li:after {
content: counter(list) ".";
position: absolute;
left: -2.5em;
width: 2em;
text-align: right;
color: red;
}
This should work:
<ol id="footnotes">
<li><span>This is the first footnote...</span></li>
<li><span>This is the second footnote...</span></li>
</ol>
#footnotes li { color: #f90; }
#footnotes li span { color: #000; }
Well, the kicker is that the numbers are technically generated inside the <li>, so anything you do to the <li> will affect the number. From the spec:
"Most block-level elements in CSS generate one principal block box.
In this section, we discuss two CSS mechanisms that cause an element
to generate two boxes: one principal block box (for the element's
content) and one separate marker box (for decoration such as a
bullet, image, or number)."
Notice that both the marker box and the principal box belong to the
same element - in this case, the list item. Accordingly, we should
expect all <li> styling to apply to both the marker and the content.
This is also not surprising if you think about it as though the list
item itself is generating the numbering content (which effectively it
is doing in CSS terms). This is confirmed later on when the spec
continues:
"The list properties allow basic visual formatting of lists. As with
more general markers, a element with 'display: list-item' generates a
principal box for the element's content and an optional marker box.
The other list properties allow authors to specify the marker type
(image, glyph, or number) and its position with respect to the
principal box (outside it or within it before content). They do not
allow authors to specify distinct style (colors, fonts, alignment,
etc.) for the list marker or adjust its position with respect to the
principal box."
So because the marker belongs to the list, it is affected by the <li> styling and isn't adjustable directly. The only way to achieve a different styling for the marker is to insert a <span> inside the list item, and style the span with the properties you want to be different from the marker.
This simple CSS3 solution works in most browsers (IE8 and up):
ul {
padding-left: 14px;
list-style: none;
}
ul li:before {
color: #f90;
content: "•";
position: relative;
left: -7px;
font-size: 18px;
margin-left: -7px;
}
You may have to adjust the padding and margin values depending on your situation.
I recently had a similar problem and found an article, Styling ordered list numbers, that describes a smart way of achieving styling of the list markers without using additional tags. The article basically says that for an ordered list:
The key is using CSS generated content to create and insert the
counter numbers after removing the default numbering from the list.
For more details please see the article.
These days you can just use ::marker;
Example:
li::marker {
color: #f90;
}
More here, including the browser compat table: https://developer.mozilla.org/en-US/docs/Web/CSS/::marker#Browser_compatibility
How about this?
<head>
<style>
#footnotes li { color: #f90; }
#footnotes li a { color: #000; }
</style>
</head>
<body>
<ol id="footnotes">
<li><a name="footnote1">This is the first footnote...</a></li>
<li><a name="footnote2">This is the second footnote...</a></li>
</ol>
</body>
Combining some of the other answers, which I found to be incomplete, I find this most complete. It considers sub style-types for different levels in the hierarchy and considers that an li may be more than one line (:after places at bottom line, so we use :before).
Note customizing of side character as well: 1. 1).Tested in Chrome.
ol { counter-reset:li; }
ol li {
list-style-type:none;
counter-increment:li;
position:relative;
}
ol li:before {
content:counter(li) ")";
position:absolute;
left: -2.6em;
width: 2em;
text-align: right;
color: #f00;
}
ol ol li:before { content:counter(li,lower-alpha) ")"; }
ol ol ol li:before { content:counter(li,lower-roman) "."; }
You can also use "outside" list-style attribute.
See here