How to use tick / checkmark symbol (✓) instead of

2019-02-01 04:47发布

I have a list where I want to add tick symbol before list text. Is there any CSS that can help me to apply this way?

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

Note: I want this in this type of HTML code

<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>

3条回答
闹够了就滚
2楼-- · 2019-02-01 05:21

You can use a pseudo-element to insert that character before each list item:

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>

查看更多
够拽才男人
3楼-- · 2019-02-01 05:23

Here are three different checkmark styles you can use:

ul:first-child  li:before { content:"\2713\0020"; }  /* OR */
ul:nth-child(2) li:before { content:"\2714\0020"; }  /* OR */
ul:last-child   li:before { content:"\2611\0020"; }
ul { list-style-type: none; }
<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>

<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>

<ul><!-- not working on Stack snippet; check fiddle demo -->
  <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>

jsFiddle

References:

查看更多
\"骚年 ilove
4楼-- · 2019-02-01 05:30

As an addition:

You can use better made checkmarks https://github.com/encharm/Font-Awesome-SVG-PNG/blob/master/black/svg/check.svg or any other icons from font awesome using

ul li:before { content: '✓'; }

Solution

Try this:

ul {
   list-style: none;
}
li {
  position: relative;
  padding-left: 40px;
}
li:before {
  position: absolute;
  top: 5px;
  left: 0;
  content: ' ';
  width: 50px;
  height: 50px;
  background: url("data:image/svg+xml;utf8,<?xml version='1.0' encoding='utf-8'?><svg width='18' height='18' viewBox='0 0 1792 1792' xmlns='http://www.w3.org/2000/svg'><path d='M1671 566q0 40-28 68l-724 724-136 136q-28 28-68 28t-68-28l-136-136-362-362q-28-28-28-68t28-68l136-136q28-28 68-28t68 28l294 295 656-657q28-28 68-28t68 28l136 136q28 28 28 68z'/></svg>") no-repeat;
}

Here you can find all icons you can use: https://github.com/encharm/Font-Awesome-SVG-PNG/tree/master/black/svg

查看更多
登录 后发表回答