如何在无序列表中使用勾号/复选标记符号(✓)而不是项目符号?

新手上路,请多包涵

我有一个列表,我想在列表文本之前添加刻度符号。是否有任何 CSS 可以帮助我以这种方式应用?

 ✓ this is my text
✓ this is my text
✓ this is my text
✓ this is my text
✓ this is my text
✓ this is my text

注意:我想要这种类型的 HTML 代码

 <ul>
  <li>this is my text</li>
  <li>this is my text</li>
  <li>this is my text</li>
  <li>this is my text</li>
  <li>this is my text</li>
</ul>

原文由 Stack-overflow-hero 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1.1k
2 个回答

您可以使用 伪元素 在每个列表项之前插入该字符:

 ul {
  list-style: none;
}

ul li:before {
  content: '✓';
}
 <ul>
  <li>this is my text</li>
  <li>this is my text</li>
  <li>this is my text</li>
  <li>this is my text</li>
  <li>this is my text</li>
</ul>

原文由 Josh Crozier 发布,翻译遵循 CC BY-SA 4.0 许可协议

截至 2022 年,我找到了最容易使用的一种。它允许指定标记的颜色。下面的CSS:

 li::marker {
  color: red;
  content: "✓";
}

原文由 Auguste Tom 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题