本文共 3910 字,大约阅读时间需要 13 分钟。
本文翻译自:
This question already has an answer here: 这个问题在这里已有答案:
Imagine a simple unsorted list with some <li>
items. 想象一下带有一些<li>
项的简单未排序列表。 Now, I have defined the bullets to be square shaped via list-style:square;
现在,我已经通过list-style:square;
定义子弹为方形list-style:square;
However, if I set the color of the <li>
items with color: #F00;
但是,如果我用颜色设置<li>
项目的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... 是否有一种优雅的方式来定义CSS中子弹的颜色......
HTML HTML
CSS CSS
li{ list-style:square;}
参考:
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 , then copy/paste your code and customize your bullets =) stills elegant? 听起来很难,但你可以制作自己的png图像/模式,然后复制/粘贴你的代码并自定义你的子弹=)仍然优雅?
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: 按照@ lea-verou关于另一个答案的想法并应用这种外部源代码增强的理念,我来到另一个解决方案:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
ie: fa-angle-right []
and use the last part of f... followed by a number like this, with the font-family
too: 并使用f的最后一部分...后跟一个这样的数字,也使用font-family
:
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 =) 现在你也有自定义项目符号提示=)
I tried this and things got weird for me. 我试过这个,事情对我来说很奇怪。 (css stopped working after the :after {content: "";}
part of this tutorial. I found you can color the bullets by just using color:#ddd;
on the li
item itself. (CSS停止后的工作:after {content: "";}
,部分本教程中,我发现,你可以通过只使用颜色子弹color:#ddd;
在li
项目本身。
Here's an . 这是一个 。
li{ color:#ff0000; list-style:square; }a { text-decoration: none; color:#00ff00;}a:hover { background-color: #ddd;}
I know it's a bit of a late answer for this post, but for reference... 我知道这篇文章有点迟到,但供参考......
CSS CSS
ul { color: red;}li { color: black;}
The bullet colour is defined on the ul tag and then we switch the li colour back. 子弹颜色在ul标签上定义,然后我们将li颜色切换回来。
I simply solve this problem like this, which should work in all browsers: 我只是像这样解决这个问题,它应该适用于所有浏览器:
HTML: HTML:
CSS: CSS:
ul li{ color: red}ul li span{ color: blue;}
Taking Lea's demo, here's a different way of making unordered lists, with borders: 以Lea的演示为例,这是一种制作无序列表的不同方式,带有边框: :
HTML HTML
CSS CSS
ul {list-style: none;margin: 0;}ul:first-child { padding: 0;}li { line-height: 180%; border-bottom: 1px dashed #CCC; margin-left: 14px; text-indent: -14px;}li:last-child { border: none;}li:before { content: ""; border-left: 4px solid #CCC; padding-left: 10px;}
转载地址:http://hscnb.baihongyu.com/