CSS3在表格列中对齐小数数据

CSS3在表格列中对齐小数数据

本文介绍了按小数点,HTML5,CSS3在表格列中对齐小数数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的问题是单元格的内容可以包含:

我建立一个wordpress插件,它生成一个HTML表格并通过短代码发送到重力形状html块。 p>


  • 23.24

  • 1,234.665

  • 123.4



等...



注意不同的小数位数。



是否有非黑客&最佳做法按小数点对齐此列数据的方式?在这种情况下,对齐权将不起作用。



插入0是不可接受的,因为这表示一定程度的准确性。



如你所见,我试图在td元素中使用 align =charchar =。



非常感谢。



有没有办法使用 printf(%8.3f,d1)或类似的,而不实际打印到屏幕?例如构造变量d1,以供以后使用,但不打印它?

解决方案

我写了一个解决这个问题的jQuery插件。可在此处找到:



使用原始HTML表格,它将按小数点对齐列:



$ table')。alignColumn(3);



这是通过添加另一个列,但最好不要破坏其他间距。在Github页面上还有一个不同的解决方案。


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:

  • 23.24
  • 1,234.665
  • 123.4

etc...

Notice the differing number of decimal places.

Is there a non-hack & best practice way of aligning this column data by decimal point? In this case, Aligning right will not work.

Inserting 0s is not acceptable because this indicates a degree of accuracy which is not there.

As you can see, I have attempted to use align="char" char="." inside the td elements with no luck.

Any help anybody can help with this would be much appreciated.

Many thanks.

Is there a way of using printf("%8.3f",d1) or similar without actually printing to the screen? e.g. structuring the variable d1 for later use but not actually printing it?

解决方案

I wrote a jQuery plugin that solves this. It's found here: https://github.com/ndp/align-column

Using your raw HTML table, it will align a column by decimal points:

$('table').alignColumn(3);

It does this by adding another column, but does its best to not corrupt the other spacing. There's also a reference to a different solution on the Github page.

这篇关于按小数点,HTML5,CSS3在表格列中对齐小数数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 08:53