【发布时间】:2020-11-17 17:42:57
【问题描述】:
我试图弄清楚为什么 MathJax 渲染块给了我错误的 div 高度。代码是
<div class="text-field" id='inner-text'>\(\sqrt{b^{a}\frac{\partial y}{\partial x}}\)</div>
使用 CSS
.text-field {
display: inline-block;
overflow: hidden;
max-width: 15em;
}
当下面的 JS sn-p 运行时
MathJax.typeset();
let text = document.getElementById("inner-text");
console.log(text.clientHeight,
text.offsetHeight,
text.getBoundingClientRect().height,
window.getComputedStyle(text).getPropertyValue('height'));
控制台给出
41 41 41.25 "41.25px"
但是,在检查元素中:
实际高度与通过 JS 访问的任何高度选项都不一致。这是怎么回事,如何才能获得准确的高度值?
【问题讨论】:
标签: javascript html css height mathjax