How to add brackets (a) to ordered list? compatible in all browsers
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-alph开发者_如何学运维a) ") ";}
li { counter-increment: section;}
but it not works in IE 7 and lower.
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) ")";
}
I use this code snippet in mediawiki with CSS enabled. I am not sure whether this will work in older versions of IE...
<style>
/* css handles the parentheses/brackets */
.laparent ol { counter-reset: item }
.laparent li { display: block ; counter-increment: item; }
/* replace the counter before list item with
open parenthesis + counter + close parenthesis */
.laparent li:before { content: " (" counter(item,lower-alpha) ") "; }
</style>
<ol class="laparent">
<li> this is the first item; </li>
<li> this is the second item; or </li>
<li> this is the third item. </li>
</ol>
Outputs:
(a) this is the first item;
(b) this is the second item; or
(c) this is the third item.
Since CSS3 the problem seems solved:
style="list-style-type: parenthesized-lower-latin;"
http://www.w3.org/TR/2011/WD-css3-lists-20110524/
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>
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
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).
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.
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) 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) A copy of the blah and blah and blah and blah and blah and blah and blah and blah.
</p>
<p> (3) Recruitment.
</p>
</div>
If your list is fixed, a workaround can be :
<ul>
<li style="list-style:symbol('(a)');">...</li>
</ul>
<ul>
<li style="list-style:symbol('(b)');">...</li>
</ul>
<ul>
<li style="list-style:symbol('(c)');">...</li>
</ul>
...
which gives
(a) ...
(b) ...
(c) ...
...
Hope this helps.
精彩评论