How to add brackets (a) to ordered list? compatibl

2019-01-23 03:36发布

问题:

I have to show like

(a)

(b)

(c)

Update:

I found a CSS way

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

but it not works in IE 7 and lower.

回答1:

This is possible with custom counters, but at least IE7- doesn't support it, some others mightn't either. See here for details: http://www.quirksmode.org/css/counter.html

Ex:

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


回答2:

I use this code snippet in mediawiki with CSS enabled. I am not sure whether this will work in older versions of 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>

Outputs:

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


回答3:

Since CSS3 the problem seems solved:

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

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



回答4:

You can't get (a) (b) (c).

You can however get the letter without the brackets:

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

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



回答5:

These are your options according to W3C.

With CSS it isn't possible. You would have to make a custom list using javascript (or similar).



回答6:

There's no built-in way to do this. Which means you enter the land of (fun) hacks.

You could try a background image of two parentheses.



回答7:

I instead made paragraphs. I indented the paragraph and then pulled out the first line, using a text-indent and numbered these myself.

.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>


回答8:

Or you can simply add the text count manually without having yo worry about browser fallbacks. Works in any browser!

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;
   */
}
<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>



标签: jquery css xhtml