Left align ol numbers with the heading in the same “column”

。_饼干妹妹 提交于 2019-12-11 12:06:08

问题


For the sake of simplicity, I've put everything in the HTML part:

<section style="text-align:center;">
  <h3>FRUITS</h3>
  <ol>
    <li>Apples</li>
    <li>Bananas</li>
    <li>Oranges</li>
  </ol>
</section>

How to make every number of ol to be aligned by the same "column"?

I would like to get this:

FRUITS
1. Apples
2. Bananas
3. Oranges

回答1:


For left align the list numbers with the heading.

body {
    text-align: center;
}
section {
    display: inline-block;
    text-align: left;
}
ol {
    list-style: none;
    padding: 0;
}
ol li {
    counter-increment: step-counter;
}
ol li:before {
    content: counter(step-counter)". ";
}
<section>
    <h3>FRUITS</h3>
    <ol>
        <li>Apples</li>
        <li>Bananas</li>
        <li>Oranges</li>
    </ol>
</section>


来源:https://stackoverflow.com/questions/33219983/left-align-ol-numbers-with-the-heading-in-the-same-column

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!