Skip ordered list item numbering

前端 未结 5 2056
轮回少年
轮回少年 2021-02-18 22:34

I have an ordered list and I\'d like to skip the number output from a particular item.

Traditional output:

1. List item
2. List item
3. List item
4. List         


        
相关标签:
5条回答
  • 2021-02-18 23:19

    The simplest way is to remove the list marker from the item to be skipped and set the number of the next item using the value attribute (which will not be deprecated/obsolete in HTML5). Example:

    <ol>
    <li>List item
    <li>List item
    <li style="list-style-type: none">List item
    <li value=3>List item
    <li>List item
    </ol>
    
    0 讨论(0)
  • 2021-02-18 23:21

    One thing I tried that seemed to work was just adding a font-size: 0. This could be applied to the aforementioned "skip" class.

    Admittedly, this solution lacks some HTML purity, but is quite simple.

    0 讨论(0)
  • 2021-02-18 23:24

    Another option is to use CSS3 counters: demo

    HTML

    <ul>
    <li>One</li>
    <li>Two</li>
    <li class="skip">Skip</li>
    <li>Three</li>
    <li>Four</li>
    </ul>​
    

    CSS

    ul {
        counter-reset:yourCounter;
    }
    ul li:not(.skip) {
        counter-increment:yourCounter;
        list-style:none;
    }
    ul li:not(.skip):before {
        content:counter(yourCounter) ".";
    }
    ul li.skip:before {
        content:"\a0\a0\a0"; /* some white-space... optional */
    }
    
    0 讨论(0)
  • 2021-02-18 23:26

    It's quite simple now.

    Just add the following to a class .skip with .skip being used for the skipped list-item:

    ol li.skip {
        list-style-type:none;
        counter-increment:none;
    }
    

    in HTML it would be:

    <ol>
      <li>first list item</li>
      <li class="skip">2nd list item</li>
      <li>third list item</li>
    </ol>
    

    resulting in:

    1. first list item
      2nd list item
    2. third list item
    0 讨论(0)
  • 2021-02-18 23:30

    This is my solution (only with CSS) that allow you to keep the normal usage of an li (list-item) from an ol (ordered list). That means all li item are consitent and there are no item that not represent the same thing as its neighbour.

    Code just below :

     .term-and-condition li {
        position: relative;
      }
      .term-and-condition ol ol {
        list-style-type: lower-latin;
      }
      .term-and-condition h2 {
        position: absolute;
        top: -2.4em;
        left: -1.5em;
      }
      .term-and-condition h3 {
        position: absolute;
        top: -2.4em;
        left: -1.5em;
      }
      .term-and-condition h2 + *,
      .term-and-condition h3 + * {
        margin-top: 4em;
      }
    <html lang="en">
      <head>
        <meta charset="UTF-8">
        <title>Skip ordered list item numbering</title>
      </head>
      <body>
        <article class="term-and-condition">
          <h1>Participants agree to be bound by these Terms and Conditions</h1>
          <ol>
            <li>
              <h2>The Promoter</h2>
              <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Veritatis dolorum consequuntur, qui cupiditate fugit quo ipsa hic, in amet libero magnam consectetur facere, accusantium sed, adipisci aliquam unde! Sit, iure.</p>
            </li>
    
            <li><p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Veritatis dolorum consequuntur, qui cupiditate fugit quo ipsa hic, in amet libero magnam consectetur facere, accusantium sed, adipisci aliquam unde! Sit, iure.</p></li> 
    
            <li>
              <h2>Eligibility</h2>
              <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Veritatis dolorum consequuntur, qui cupiditate fugit quo ipsa hic, in amet libero magnam consectetur facere, accusantium sed, adipisci aliquam unde! Sit, iure.</p>
            </li>
    
            <li>
              <h2>Entry</h2>
              <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Veritatis dolorum consequuntur, qui cupiditate fugit quo ipsa hic, in amet libero magnam consectetur facere, accusantium sed, adipisci aliquam unde! Sit, iure.</p>
            </li>
    
            <li><p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Veritatis dolorum consequuntur, qui cupiditate fugit quo ipsa hic, in amet libero magnam consectetur facere, accusantium sed, adipisci aliquam unde! Sit, iure.Lorem ipsum dolor sit amet, consectetur adipisicing elit. Veritatis dolorum consequuntur, qui cupiditate fugit quo ipsa hic, in amet libero magnam consectetur facere, accusantium sed, adipisci aliquam unde! Sit, iure.</p></li>
    
            <li><p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Veritatis dolorum consequuntur, qui cupiditate fugit quo ipsa hic, in amet libero magnam consectetur facere, accusantium sed, adipisci aliquam unde! Sit, iure.</p> </li>
    
            <li>
              <p>Entrants must upload an image and text that:</p>
              <ol>
                <li><p>Lorem ipsum dolor sit amet, qui cupiditate fugit quo ipsa hic, in amet libero magnam consectetur facere</p></li>
                <li><p>consectetur adipisicing elit. Veritatis dolorum consequuntur,</p></li>
                <li><p>in amet libero magnam consectetur facere,</p></li>
                <li><p>accusantium sed, adipisci aliquam unde! Sit, iure.</p></li>
                <li>
                  <h3>Additional requirements</h3>
                  <p>All entries must be the participant’s own image or have the relevant permission</p>
                </li>
                <li><p>The entrant must be the lorem</p></li>
              </ol>
            </li>
            <li>
            <h2>Winner Selection</h2> 
              <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Suscipit tenetur minus dolores! Natus harum pariatur voluptas, voluptatibus magnam, animi explicabo eos laudantium delectus nobis repellat dicta eveniet, et blanditiis ducimus!</p>
            </li>
          </ol>
        </article>
      </body>
    </html>

    — See the Codepen

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