b24
b24

Reputation: 2473

add padding for RTL content after use row_number CSS

I used below CSS code for add row number to a table rows:

table {
    direction: rtl;
    counter-reset: line-number;
}

td:first-child {
    text-align: right !important;
}

td:first-child:before {
    content: counter(line-number) ".";
    counter-increment: line-number;
    padding-right: 0.3em;
    color: lightgray;
}

but it's content not align right after tenth row. See below image:

row number padding issue

But I want something like this:

row_number2

I also try add padding but it's not a working solution.

How fix this?

This is my Fiddle now.

Upvotes: 0

Views: 353

Answers (2)

Abhishek Pandey
Abhishek Pandey

Reputation: 13568

You can set min-width of td:first-child:before.

td:first-child:before {
content: counter(line-number) ".";
counter-increment: line-number;
padding-right: 0.3em;
color: lightgray;
min-width: 20px;
display: inline-block;
}

Upvotes: 2

Randy
Randy

Reputation: 9849

Make sure you put the number in an element, like this:

<input type="checkbox"> <div class="number">10</div>

Then you can style that element, to have a minimum width:

.number {
   min-width:20px;
}

That way they have the same with, and you don't need funny padding depending on how many digits the number has.

Upvotes: 0

Related Questions