How to center ordered list number in HTML

前端 未结 4 1401
误落风尘
误落风尘 2021-01-07 17:15

I am currently learning HTML programming. I have a problem:

If I put like this:



HEADLINE
相关标签:
4条回答
  • 2021-01-07 17:53

    This is very old post but this this is the solution I did.

    CSS:

    .center
    {
     text-align: center;
     list-style-position: inside;
    }
    ol.center li
    {
     text-align: left;
     margin-left: 45%;
    }
    

    HTML

    <ol class="center">Lorem ipsum dolor sit amet consectetur adipisicing elit. Reprehenderit, repellat.
    <li>List1<li>
    <li>List2<li>
    </ol>
    

    Final Result would look lke this :

    0 讨论(0)
  • 2021-01-07 17:55

    Further to Nuno Duarte's answer you can add breaks after list numbers which (I think) makes it look better in centered mode. (disclaimer: Not tested across browsers)

    .text-center {
        text-align: center;
    }
    ol.text-center {
        list-style-position: inside;
        padding-left: inherit; /*Get rid of padding to center correctly*/
    }
        ol.text-center > li::before {
            content: "\A";
            white-space: pre;
        }
    <h4 class="text-center">HEADLINE</h4>
    <ol class="text-center">
      <li>First Item</li>
    </ol>

    0 讨论(0)
  • 2021-01-07 17:58

    You are aligning texts in the body.

    Try this:

    .center {
      text-align: center;
      list-style-position: inside;
    }
    <h4 align="center">HEADLINE</h4>
    <ol class="center">
      <li>First Item</li>
    </ol>

    0 讨论(0)
  • 2021-01-07 18:03

    Nikolas, aligning the numbers on an ordered list in CSS is as follows:

         ol
        {
           display: inline-block;
           margin-left: auto;
           margin-right: auto;
        }
    

    **You must use a display-block because you need to put your list in a box for it to center the numbers with the list.

    0 讨论(0)
提交回复
热议问题