如何将括号(a)添加到有序列表中?兼容所有浏览器

时间:2010-04-01 05:41:28

标签: jquery css xhtml

我必须表现出像

(a)中

(b)中

(c)中

更新:

我发现了一种CSS方式

ol {list-style-type: none;}
li:before {content: "(" counter(section, lower-alpha) ") ";}
li { counter-increment: section;}

但它不适用于IE 7及更低版本。

8 个答案:

答案 0 :(得分:9)

这可以使用自定义计数器,但至少IE7-不支持它,其他一些也可能不支持。有关详细信息,请参阅此处:http://www.quirksmode.org/css/counter.html

例如:

li:before {
    content: "(" counter(mycounter,lower-latin) ")";
}

答案 1 :(得分:4)

我在启用了CSS的mediawiki中使用此代码段。我不确定这是否适用于旧版本的IE ...

{{#css:
  .laparent ol { counter-reset: item }
  .laparent li { display: block ; counter-increment: item; }
  .laparent li:before { content: " ("counter(item,lower-alpha)") "; }
}}
<ol class=laparent>
   <li> this is the first item;
   <li> this is the second item; or
   <li> this is the third item.
</ol>

输出:

(a) this is the first item;
(b) this is the second item; or
(c) this is the third item. 

答案 2 :(得分:1)

由于CSS3问题似乎已经解决了:

style="list-style-type: parenthesized-lower-latin;"

http://www.w3.org/TR/2011/WD-css3-lists-20110524/

答案 3 :(得分:0)

你不能得到(a)(b)(c)。

可以获得没有括号的字母:

<ul style="list-style-type: lower-latin;">...</ul>

请参阅http://www.w3schools.com/CSS/tryit.asp?filename=trycss_list-style-type_all

答案 4 :(得分:0)

根据W3C,

These are your options

使用CSS是不可能的。您必须使用javascript(或类似)制作自定义列表。

答案 5 :(得分:0)

没有内置方法可以做到这一点。这意味着你进入(有趣)黑客的土地。

您可以尝试两个括号的背景图片。

答案 6 :(得分:0)

我改为做了段落。我缩进了段落然后拉出第一行,使用文本缩进并自己编号。

.list_indent {
margin-left:48px;
}
.list_indent p {
text-indent:-26px;
}

<div class="list_indent">  
<p> (1)&nbsp;&nbsp;The recruitment report and a copy of the blah and blah and blah and blah and blah and blah and blah and blah.;
</p>   
<p> (2)&nbsp;&nbsp;A copy of the blah and blah and blah and blah and blah and blah and blah and blah.
</p>     
<p> (3)&nbsp;&nbsp;Recruitment.
</p>   
</div>

答案 7 :(得分:0)

或者您可以手动添加文本计数,而无需担心浏览器回退。适用于任何浏览器!

&#13;
&#13;
ul.abc-list {
  list-style: none;
  padding-left: 30px;
}
ul.abc-list > li > span.counter {
  position: absolute;
  margin-left: -20px;
  /*if you want to right align the text
   * 
   * width: 15px;
   * text-align: right;
   */
}
&#13;
<ul class="abc-list">
  <li><span class="counter">a)</span> One</li>
  <li><span class="counter">b)</span> Two</li>
  <li><span class="counter">c)</span> Three</li>
  <li><span class="counter">d)</span> Four</li>
  <li><span class="counter">e)</span> Five</li>
  <ul>
&#13;
&#13;
&#13;

相关问题