作者:你有小号我就不能有吗_477 | 来源:互联网 | 2022-12-01 20:00
有这种情况:
需要获取red box
文本区域内部的大小。基本上是文本的尺寸,而不是文本区域的尺寸。
html代码就是这样:
有没有办法使用Angular4 +或Javascript实现这一目标?
1> iLuvLogix..:
编辑:
要计算任意字符串的宽度,可以使用以下方法:
var fOntSize= 12;
var widthTest = document.getElementById("widthTest");
widthTest.style.fOntSize= fontSize;
var height = (widthTest.clientHeight + 1) + "px";
var width = (widthTest.clientWidth + 1) + "px"
console.log(height, width);
#widthTest
{
position: absolute;
visibility: hidden;
height: auto;
width: auto;
white-space: nowrap;
}
FooBarEatsBarFoodBareFootWithBarFoo