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


当前回答

你可以给<li>元素一个padding-left。

其他回答

似乎您可以(在某种程度上)使用<li>标记上的填充来控制间距。

<style type="text/css">
    li { padding-left: 10px; }
</style>

问题是,它似乎不允许你像最后一个例子那样舒适地挤压它。

为此,您可以尝试关闭list-style-type并使用&bull;

<ul style="list-style-type: none;">
    <li>&bull;Some list text goes here.</li>
</ul>

在li上使用文本缩进效果最好。

文本缩进:-x px;会让子弹更靠近李,反之亦然。

在IE的旧版本中,在负左边使用相对span可能无法正常工作。 附注:尽量避免给出职位。

ul
{
list-style-position:inside;
} 

定义和用法

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

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

使用padding-left: 1 em;文本缩进:<li>标签的-1em。 然后,list-style-position:用于<ul>标记。

<ul style='list-style-position: inside;'>
  <li style='padding-left: 1em; text-indent: -1em;'>Item 1</li>
</ul>

下面是另一个使用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
    }

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