有序列表css和子部分

时间:2013-06-26 13:55:25

标签: html css list

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

What i want it do be

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

what it is so far

到目前为止我的代码:

<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>

5 个答案:

答案 0 :(得分:2)

尝试修改你的li风格:

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

并添加:

 li p { padding-left: 10px; }

答案 1 :(得分:1)

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

答案 2 :(得分:1)

您可以将填充设置为0

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

如果你想稍微推动它,你甚至可以玩

list-style-position: outside/inside/inherit

答案 3 :(得分: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>

答案 4 :(得分: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>