我有一个有序列表,我想跳过特定项目的数字输出。
传统输出:
1. List item
2. List item
3. List item
4. List item
5. List item
期望的输出:
1. List item
2. List item
Skipped list item
3. List item
4. List item
5. List item
这可以在CSS中实现吗?我之前发现了一个我不知道的<ol>
"start" attribute,但似乎没有帮助我。
答案 0 :(得分:26)
最简单的方法是从要跳过的项目中删除列表标记,并使用the value
attribute设置下一个项目的编号(在HTML5中不会弃用/废弃)。例如:
<ol>
<li>List item
<li>List item
<li style="list-style-type: none">List item
<li value=3>List item
<li>List item
</ol>
答案 1 :(得分:18)
另一种选择是使用CSS3计数器: 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 */
}
答案 2 :(得分:3)
现在很简单。
只需将以下内容添加到.skip类中,并将.skip用于跳过的列表项:
ol li.skip {
list-style-type:none;
counter-increment:none;
}
HTML中的将是:
<ol>
<li>first list item</li>
<li class="skip">2nd list item</li>
<li>third list item</li>
</ol>
导致:
答案 3 :(得分:1)
这是我的解决方案(仅限CSS),允许您从ol(有序列表)保持li(列表项)的正常使用。这意味着所有li
项都是有意义的,并且没有任何项目与其邻居不相同。
下面的代码:
.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>
答案 4 :(得分:0)
我尝试似乎起作用的一件事是添加了font-size:0。这可以应用于上述“ skip”类。
诚然,此解决方案虽然缺乏HTML的纯净性,但非常简单。