3

我正在尝试创建一个有序列表,其中包含十进制和 css-ing 的小节,如下图所示。

我想要它做什么

但到目前为止,我只设法得到了这个(下面的下一张图片),它现在有数字,但它们已经对齐了。

到目前为止是什么

到目前为止,这是我的代码:

<style>
    body{
        width: 500px;
        font-family: helvetica;
        font-size: 12px;
        counter-reset:section;
    }

    OL { counter-reset: item }
    LI { display: block }
    LI:before { content: counters(item, ".") " "; counter-increment: item }
    p{
        display:inline-block;
        width: 400px;
    }

</style>

<ol>
  <li>
    <strong>The Card</strong>
    <ol>
        <li><p>When you receive your Card, you will receive a PUK and you must choose a PIN.</p></li>
        <li><p>You must either memorise the PIN or keep record of it in a safe place, separate from your Card. Do not tell anyone your PUK or PIN.</p></li>
    </ol>
    </li>
</ol>
4

5 回答 5

2

尝试像这样修改您的 li 样式:

 OL { margin-left: 0; padding-left: 0; }

并添加:

 li p { padding-left: 10px; }
于 2013-06-26T13:57:06.710 回答
1

添加vertical-align: top;到您的li:beforeCSS 规则。您可能还需要使用<p> marginCSS 属性,具体取决于您希望如何对齐元素。

于 2013-06-26T14:00:34.293 回答
1

您可以将填充设置为 0

li p {padding: 0; display: block;}

如果你想稍微推动一下,你甚至可以玩弄

list-style-position: outside/inside/inherit
于 2013-06-26T14:01:38.083 回答
0

这就是我得到的

body{
        width: 500px;
        font-family: helvetica;
        font-size: 12px;
        counter-reset:section;
    }

    OL { 
        counter-reset: item; 
        margin: 0px;
        padding: 0px;
    }
    LI { 
        display: block;

    }
    LI:before { 
        content: counters(item, ".") " "; 
        counter-increment: item ;
        vertical-align: top;
    }
    p{
        display:inline-block;
        width: 400px;
        margin-top: 0px;
        margin-left: 50px;
    }
    strong{
        margin: 0px;
        padding: 0px;
        margin-left: 20px;
    }

    ol li ol{
        margin-top: 20px;
        margin-botom: 20px;
    }


</style>
于 2013-06-26T14:21:27.327 回答
0

你去(完全如你所愿):JSFiddle


CSS

body {
    width: 500px;
    font-family: helvetica;
    font-size: 12px;
    counter-reset:section;
}
ol li ol {
    padding-left:0px;
}
ol li ol li {
    padding-left:20px;
}

HTML

<ol>
    <li> <strong>The Card</strong>

        <ol>
            <li>
                <p>When you receive your Card, you will receive a PUK and you must choose a PIN.</p>
            </li>
            <li>
                <p>You must either memorise the PIN or keep record of it in a safe place, separate from your Card. Do not tell anyone your PUK or PIN.</p>
            </li>
        </ol>
    </li>
</ol>
于 2013-06-26T14:29:06.940 回答