可以td内的文本与td一起调整大小吗? (是其高度的百分比?) [英] Can the text inside a td resize along with the td? (be a percentage of its height?)
问题描述
我有一个表是100%的屏幕,里面有3x3 = 9个单元格,每个33%。
到目前为止很好。它是一个干净,可扩展的tic-tac-toe的东西。
I have a table which is 100% of the screen, and inside it there are 3x3 = 9 cells, 33% each. So far so good. Its a clean, scalable tic-tac-toe thing.
问题是,TD中的文本不沿着缩放。
The problem is that the text inside the TDs does not scale along.
有没有什么方法可以说我要的文字大小是TD高度的30%?或者某些
Is there some way to say "I want the text size to be 30% of the height of the TD" ? Or something
PS:我试过font-size:50%,但它不工作。这意味着父字体大小的50%,这是一些固定值(以像素为单位)。所以它不动态。
PS: I tried font-size:50%, but it does not work. This means 50% of the parent font size, which is some fixed value in pixels. So its not dynamic.
推荐答案
这可以用JavaScript。
This is possible with JavaScript.
<body onload="resizeFontSize();" onresize="resizeFontSize();">
<div style="width: 100%" id="el">Content</div>
</body>
而且函数:
function resizeFontSize(){
element = document.getElementById('el');
element.style.fontSize = (element.offsetHeight * 0.3) + 'px';
}
这篇关于可以td内的文本与td一起调整大小吗? (是其高度的百分比?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!