简体   繁体   English

HTML有序列表-具体顺序

[英]HTML ordered list - specific order

in HTML/CSS, is it possible to have my ordered list in the following format? 在HTML / CSS中,是否可以使用以下格式显示我的订购清单?

  o. Item 1
  i. Item 2
 ii. Item 3
iii. Item 4

More generally, is it possible to create my own format for ordered lists? 更一般而言,是否可以为有序列表创建自己的格式?

Sure, you could use the <ol> tag for roman numerals simply by adding a type. 当然,只需添加类型即可将<ol>标记用于罗马数字。

<ol type="i">
  <li>Coffee</li>
  <li>Tea</li>
  <li>Milk</li>
</ol>

This HTML spits out: 该HTML弹出:

i. Coffee
ii. Tea
iii. Milk

More information can be found here: http://www.w3schools.com/tags/att_ol_type.asp 可以在这里找到更多信息: http : //www.w3schools.com/tags/att_ol_type.asp

For you o being the first position item, start your count at the second item and prepend the first one using Javascript or jQuery. 对于你o成为第一个位置的项目,在第二个项目启动计数和在前面加上使用Javascript或jQuery的第一个。

So what you want is an arbitrarily styled first element. 因此,您想要的是任意样式的第一个元素。 All subsequent list items should then have a number text which is one lower than their natural ordering would suggest. 然后,所有后续列表项都应具有一个数字文本,该数字比其自然顺序建议的数字低一个。 Correct? 正确?

Thus, your HTML List is simply: 因此,您的HTML列表很简单:

<ol>
  <li>Item 1</li>
  <li>Item 2</li>
  <li>Item 3</li>
  <li>Item 4</li>
</ol>

The following CSS does the actual magic. 以下CSS发挥了真正的魔力。 However (minor drawback), I believe you need to set the width of the :before pseudo-element explicitly in order to resemble the appearance of an "ordinary" list. 但是(微小的缺点),我相信您需要显式设置:before伪元素的宽度,以类似于“普通”列表的外观。

ol {
  list-style-type: none;
}

li {
  counter-increment: strangecounter;
}

li:before {
  content: counter(strangecounter, lower-roman) ". ";
  display: inline-block;
  width: 2em;
  text-align: right;
  margin-right: 0.5em;
}

ol :first-child {
  counter-reset: strangecounter -1;
}

ol :first-child:before {
  content: "o. ";
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM