Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

right-align CSS before: numbers?

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?

like image 724
Maxor Avatar asked Jan 12 '23 07:01

Maxor


1 Answers

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;
}
like image 167
andi Avatar answered Jan 14 '23 19:01

andi