问题已经很清楚了。我需要在HTML中显示平方根符号内的数字。这是否可能?如果不可能,最好的选择是什么?(除了设计hr元素的平方根形状之外)
<span style="white-space: nowrap">
√<span style="text-decoration:overline;"> X + 1 </span>
</span>
首先,如果你不反对使用外部库。
那么就可以直接使用mathjax js库。
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<script id="MathJax-script" async
src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js">
</script>
<p>
$$ \sqrt{22b^3-c} \over 3b $$
</p>
使用本地解决方案
您可以使用UTF-8的组合字符代码̅
。它将在前一个代码块上方添加上划线。
但是一定要注意您的字体设置。根据字体不同,它们可能显示为单独的上划线,连续的上划线(甚至作为单独的字符)。 (使用“运行代码段”检查下面的行为)
<p>Stack-overflows font settings results in continuous overline for combining characters in textarea in (Chrome on OsX)</p>
<textarea>
√2̅2̅
</textarea>
<p>
Stack-overflows stylesheet results in separated overlines for combining characters in paragraph (Chrome on OsX)
</p>
<p>
√2̅2̅ <span style="font-family: Courier">
(in Courier √2̅2̅ )
</span>
</p>
√2
.sqrt {
align-items: baseline;
padding-top: 8px;
}
.sqrt span {
margin-left: -1ch;
position: relative;
}
.sqrt>span:after {
content: '';
position: absolute;
width: var(--char);
height: 0.1em;
top: 0;
left: 1ch;
background-color: var(--color);
}
<samp class="sqrt" style="--char: 1ch; --color: white;">
2
<span>
<svg style="width: 1ch;" xmlns="http://www.w3.org/2000/svg" xml:space="preserve" fill-rule="evenodd" stroke-miterlimit="2" clip-rule="evenodd" viewBox="0 0 59 100">
<path fill="none" stroke="#000" stroke-width="5.5" d="M13.7 62.1 1.4 69.5"/>
<path fill="none" stroke="#000" stroke-width="7.8" d="M30.9 96.3 9.2 62.2"/>
<path fill="none" stroke="#000" stroke-miterlimit="1.5" stroke-width="4.2" d="M35.9 98h-6.1l-1.4-2.3"/>
<path fill="none" stroke="#000" stroke-width="7.8" d="M55 0v2.6L32.2 99"/>
</svg>
<span>6</span>
</span>
</samp>