Align Decimal Data in table column by decimal point, HTML5, CSS3

前端 未结 7 1860
有刺的猬
有刺的猬 2020-12-17 21:58

I am building a wordpress plugin which is generating an HTML table and sending to gravityforms html block via shortcode.

My problem is that cell contents can contain

7条回答
  •  我在风中等你
    2020-12-17 22:28

    The thing is, you've gotta ensure that they all have the same number of digits after the decimal.

    Once you do that, use text-align. All it will take is a: style='text-align: right'

    Better still, you could use a css class instead of inline styles. Your markup would look like this:

     Item 115£123.25
    

    Then in your stylesheet:

    td.price{
      text-align: right;
    }
    

    With php, you can format a number as a string with number_format. You don't have to echo it or print it, just wrap your variable in that function. For example:

    $table .= "£" . $price . "";
    

    becomes:

    $table .= "£" . number_format($price,3) . "";
    

提交回复
热议问题