HTML list-style-type dash

2020-01-27 10:08发布

Is there a way to create a list-style in HTML with a dash (i.e. - or – – or — —) i.e.

<ul>
  <li>abc</li>
</ul>

Outputting:

- abc

It's occurred to me to do this with something like li:before { content: "-" };, though I don't know the cons of that option (and would be much obliged for feedback).

More generically, I wouldn't mind knowing how to use generic characters for list items.

17条回答
成全新的幸福
2楼-- · 2020-01-27 10:12

What worked for me was

<ul>
    <li type= "none">  &ndash; line 1 </li>
    <li type= "none">  &ndash; line 2 </li>
    <li type= "none">  &ndash; line 3 </li>
</ul>
查看更多
爱情/是我丢掉的垃圾
3楼-- · 2020-01-27 10:14

CSS:

li:before {
  content: '— ';
  margin-left: -20px;
}

li {
  margin-left: 20px;
  list-style: none;
}

HTML:

<ul>
  <li>foo</li>
  <li>bar</li>
</ul>
查看更多
何必那么认真
4楼-- · 2020-01-27 10:15

Use this:

ul
{
    list-style: square inside url('data:image/gif;base64,R0lGODlhBQAKAIABAAAAAP///yH5BAEAAAEALAAAAAAFAAoAAAIIjI+ZwKwPUQEAOw==');
}
查看更多
beautiful°
5楼-- · 2020-01-27 10:16
ul {
margin:0;
list-style-type: none;
}
li:before { content: "- ";}
查看更多
家丑人穷心不美
6楼-- · 2020-01-27 10:18

Here's a version without any position relative or absolute and without text-indent:

ul.dash {
    list-style: none;
    margin-left: 0;
    padding-left: 1em;
}
ul.dash > li:before {
    display: inline-block;
    content: "-";
    width: 1em;
    margin-left: -1em;
}

Enjoy ;)

查看更多
做个烂人
7楼-- · 2020-01-27 10:18

My solution is in adding extra span tag with mdash in it:

<ul class="mdash-list">
    <li><span class="mdash-icon">&mdash;</span>ABC</li>
    <li><span class="mdash-icon">&mdash;</span>XYZ</li>
</ul>

and adding to css:

ul.mdash-list 
{
    list-style:none;
}

ul.mdash-list  li
{
    position:relative;
}

ul.mdash-list li .mdash-icon
{
    position:absolute;
    left:-20px;
}
查看更多
登录 后发表回答