Html 如何设置ul/li项目符号点颜色?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7069096/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 10:05:16  来源:igfitidea点击:

how to set ul/li bullet point color?

htmlcss

提问by Steven Zack

Possible Duplicate:
Change bullets color in a list without span

可能的重复:
在没有跨度的列表中更改项目符号颜色

Normally, the bullet point in ul/li is a black solid circle. I want to change the style of it, like I want to set the color of the bullet point to be green, I also want to change the bullet point to be a square. Anyone knows how to do that?

通常,ul/li 中的要点是黑色实心圆圈。我想改变它的样式,比如我想将项目符号的颜色设置为绿色,我也想将项目符号更改为正方形。有谁知道怎么做?

回答by Evan Mulawski

Apply the color to the liand set the span(or other child element) color to whatever color the text should be.

将颜色应用于li并将span(或其他子元素)颜色设置为文本应具有的任何颜色。

ul
{
    list-style-type: square;
}

ul > li
{
    color: green;
}

ul > li > span
{
    color: black;
}

JSFiddle

JSFiddle

回答by zzzzBov

A couple ways this can be done:

有几种方法可以做到这一点:

This will make it a square

这将使它成为一个正方形

ul
{
  list-style-type: square;
}

This will make it green

这将使它变绿

li
{
  color: #0F0;
}

This will prevent the text from being green

这将防止文本变为绿色

li p
{
  color: #000;
}

However that will require that all text within lists be in paragraphs so that the color is not overridden.

但是,这将要求列表中的所有文本都在段落中,以便不会覆盖颜色。

A better way is to make an image of a green square and use:

更好的方法是制作绿色方块的图像并使用:

ul
{
  list-style: url(green-square.png);
}

回答by jondavidjohn

I believe this is controlled by the css colorproperty applied to the element.

我相信这是由color应用于元素的 css属性控制的。

回答by tcnarss

http://www.w3schools.com/cssref/pr_list-style-type.asp

http://www.w3schools.com/cssref/pr_list-style-type.asp

You need to use list-style-type:to change bullet type/style and the above link has all of the options listed. As others have stated the color is changed using the colorproperty on the ulitself

您需要使用list-style-type:来更改项目符号类型/样式,并且上面的链接列出了所有选项。正如其他人所说,颜色是使用本身的color属性改变的ul

To create 'black filled' bullets, use 'disc' instead of 'circle',i.e.:

要创建“黑色填充”项目符号,请使用“圆盘”而不是“圆圈”,即:

list-style-type:disc

列表样式类型:光盘