right-align CSS before: numbers?

断了今生、忘了曾经 提交于 2019-12-12 13:16:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!