How to center right-aligned numbers in table column using CSS?

前端 未结 11 2272
傲寒
傲寒 2021-02-02 10:54

The picture below illustrates what I\'m trying to accomplish:

\"enter

UPD. As you

11条回答
  •  渐次进展
    2021-02-02 11:32

    Seems to me that you need to have a second table inside your main table to determine the width of the numbered content to be centered but right aligned. Checkout out this fiddle: Fiddle Example

    Example Code:

    HTML:

    Some Title for Numbers in a Table
    5 000 000
    5 000
    5
    5 000 000

    CSS:

    .container {
        width: 400px;
        border: 1px solid #999;    
    }
    
    .title {
        font-weight: bold;
        text-align: center;    
    }
    
    .container table {
        margin: 0px auto;   
    }
    
    .container table td {
        text-align: right;
    }​
    

提交回复
热议问题