我想控制子弹在<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
    }

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

其他回答

这个应该可以了。一定要把子弹对准外面。你也可以使用CSS伪元素,如果你可以在IE7中向下放置它们。我真的不推荐使用伪元素来做这种事情,但它确实可以控制距离。

ul { list-style: circle outside; width: 100px; } li { padding-left: 40px; } .pseudo, .pseudo ul { list-style: none; } .pseudo li { position: relative; } /* use ISO 10646 for content http://la.remifa.so/unicode/named-entities.html */ .pseudo li:before { content: '\2192'; position: absolute; left: 0; } <ul> <li>Any Browser really</li> <li>List item <ul> <li>List item</li> <li>List item</li> </ul> </li> </ul> <ul class="pseudo"> <li>IE8+ only</li> <li>List item <ul> <li>List item with two lines of text for the example.</li> <li>List item</li> </ul> </li> </ul>

ul
{
list-style-position:inside;
} 

定义和用法

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

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

对于list-style-type: inline:

它几乎和DSMann8的答案一样,但css代码更少。

你只需要

<style>
    li:before {
        content: "";
        padding-left: 10px;
    }
</style>

<ul>
    <li>Some content</li>
</ul>

干杯

把它的内容放在一个相对定位的span中,然后你可以通过span的left属性来控制空间。

李跨度{ 位置:相对; 左:-10 px; } < ul > <李> < span >第1项< / span > < /李> <李> < span >第二项< / span > < /李> <李> < span >项3 < / span > < /李> < / ul >

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

优点:

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

缺点:

试一试 来 找到 一:)