问题
I want to have numbered paragraphs without resorting to using ordered lists. I'm trying to accomplish this by using content:counter(paragraph) in CSS so that every paragraph block I create generates a number to the left of it.
.pass {
counter-reset:paragraph;
}
.pass p:before {
content:counter(paragraph);
position:absolute;
font-size:0.6em;
color:#999;
margin-left:-3em;
counter-increment: paragraph;
}
It works fine, but the problem is I can't figure out how to align the numbers so that they all align to the right.
So instead of:
7 Content
8 Content
9 Content
10 Content
I want them to look like this:
7 Content
8 Content
9 Content
10 Content
Is there a way to accomplish this without OL and LI?
回答1:
Set a width for the :before class, then text-align:right. http://jsfiddle.net/QAX8m/
.pass {counter-reset:paragraph;}
.pass p {padding-left:40px;}
.pass p:before {
content:counter(paragraph);
counter-increment: paragraph;
position:absolute;
left:0;
width:40px;
text-align:right;
}
来源:https://stackoverflow.com/questions/18990761/right-align-css-before-numbers