由于 PHP 在服务器上运行,因此无法单独使用 PHP 来做到这一点。文本的大小取决于客户端的操作系统、浏览器(以及缩放等浏览器设置)。不过,您可以使用 javascript 来获取元素渲染后的大小。
height = document.getElementById("elementId").style.height; // Will return 176px for example
width = document.getElementById("elementId").style.width; // Will return 176px for example
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助