Html Table - 最大化单元格中的字体大小
我希望对我当前的项目有一些帮助或建议。
我有一个带有 html 表单的简单网页,其中查询数据库,结果将各种行和列返回到表中。
我需要表格做的是最大化表格单元格中文本的大小。表格单元格大小应该均匀,但单元格中的文本尽可能大。
我尝试过 jQuery BigText 和 jTextFill,但它们似乎都依赖于固定的宽度/高度。由于每个数据库查询返回不同数量的行/列,我无法设置固定的宽度/高度,因为它不会通过小表结果最大化屏幕。
<代码>
I would appreciate some help or suggestions with my current project.
I have a simple webpage with an html form where a database is queried and the results return various rows and columns into a table.
What I need the table to do is maximize the size of text in the table cells. The tables CELL size should be even, but the text in the cell be as large as possible.
I've tried jQuery BigText and jTextFill, but they both seem to depend on a fixed width/height. As each database query returns various number of rows / columns, I can't set a fixed width/height as it would not maximize the screen with a small table result.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
刚刚做完这个。它使用 jQuery 主要是为了方便/兼容性。将 HTML 表格变成扩展宽度的字体表格。
http://jsfiddle.net/fnbrb/1/
这是经过一番摆弄之后的结果。也许这样效果更好:
http://jsfiddle.net/xXHLc/11/
这是JS,但它需要一些样式还有:
Just finished this. It uses jQuery mostly for convenience/compatibility. Turns your HTML table into an expanding width font table.
http://jsfiddle.net/fnbrb/1/
Here it is after some more fiddling. Maybe this works better:
http://jsfiddle.net/xXHLc/11/
Here is the JS but it requires a few styles as well:
我不认为 HTML/Javascript 中有任何字体度量功能。在某些 UI 库中,您可以使用它们在渲染之前测量不同字体大小的字符串。如果没有这个,您可以诉诸类似下面的代码,但它是一种黑客。也许有人会知道更好的方法。
此代码测试渲染字符串,查看它们的
offsetWidth
,然后再次渲染它们,增大它们的字体大小,直到它们与最大字符串的宽度大致相同。I don't think there any font metrics functions in HTML/Javascript. In some UI libraries you can use them to measure a string at different font sizes before rendering it. Without that, you could resort to something like the code below, but it is kind of a hack. Maybe someone will know a better way.
This code test renders the strings, to look at their
offsetWidth
, and then renders them again, bumping their font sizes until they are about the same width as the largest string.