我想控制子弹在<ol>或<ul>中向右推动<li>的水平空间。

也就是说,不是一直都有

*  Some list text goes
   here.

我希望能把它变成

*         Some list text goes
          here.

or

*Some list text goes
 here.

我环顾四周,但只能找到将整个街区向左或向右移动的说明,例如http://www.alistapart.com/articles/taminglists/


当前回答

下面是另一个使用css计数器和伪元素的解决方案。我发现它更优雅,因为它不需要使用额外的html标记或css类:

    ol,
    ul {
        list-style-position: inside;
    }
    
    li {
        list-style-type: none;
    }
    
    ol {
        counter-reset: ol; //reset the counter for every new ol
    }
    
    ul li:before {
            content: '\2022 \00a0 \00a0 \00a0'; //bullet unicode followed by 3 non breakable spaces
    }
    
    ol li:before {
            counter-increment: ol;
            content: counter(ol) '.\00a0 \00a0 \00a0'; //css counter followed by a dot and 3 non breakable spaces
    }

我使用不可分割的空格,以便空格只影响列表元素的第一行(如果列表元素超过一行长)。你可以在这里使用填充。

其他回答

您还可以使用背景图像替换作为替代方案,让您完全控制垂直和水平定位。

请看这个问题的答案

您可以使用ul li:before和背景图像,并分别将position: relative和position:absolute分配给li和li:before。通过这种方式,您可以创建一个图像,并将其定位到任何您想要相对于li的位置。

老问题了,但仍然相关。 我建议使用负文本缩进。 List-style-position必须在外部。

优点:

子弹自动定位正确 改变字体大小不会破坏项目符号的位置 没有额外的元素(也没有::伪元素) 适用于RTL和LTR而不改变CSS。

缺点:

试一试 来 找到 一:)

ul
{
list-style-position:inside;
} 

定义和用法

list-style-position属性指定列表项标记应该出现在内容流内部还是外部。

来源:http://www.w3schools.com/cssref/pr_list-style-position.asp

下面是另一个使用css计数器和伪元素的解决方案。我发现它更优雅,因为它不需要使用额外的html标记或css类:

    ol,
    ul {
        list-style-position: inside;
    }
    
    li {
        list-style-type: none;
    }
    
    ol {
        counter-reset: ol; //reset the counter for every new ol
    }
    
    ul li:before {
            content: '\2022 \00a0 \00a0 \00a0'; //bullet unicode followed by 3 non breakable spaces
    }
    
    ol li:before {
            counter-increment: ol;
            content: counter(ol) '.\00a0 \00a0 \00a0'; //css counter followed by a dot and 3 non breakable spaces
    }

我使用不可分割的空格,以便空格只影响列表元素的第一行(如果列表元素超过一行长)。你可以在这里使用填充。