--- title: text-underline-position slug: Web/CSS/text-underline-position translation_of: Web/CSS/text-underline-position --- <p>{{CSSRef}}</p> <div>当 {{cssxref("text-decoration")}}属性的值设置为 <code>underline</code> 之后,可以用 <strong><code>text-underline-position</code></strong> 属性为其设置下划线的位置。</div> <div> </div> <pre class="brush:css no-line-numbers">/* 只设置一个属性值 */ text-underline-position: auto; text-underline-position: under; text-underline-position: left; text-underline-position: right; /* 设置多个属性值 */ text-underline-position: under left; text-underline-position: right under; /* 全局属性值 */ text-underline-position: inherit; text-underline-position: initial; text-underline-position: unset; </pre> <p>{{cssinfo}}</p> <h2 id="语法">语法</h2> <h3 id="属性值">属性值</h3> <dl> <dt><code>auto</code></dt> <dd>{{glossary("user agent", "用户代理")}} 会根据自己的算法来确认下划线是放在字母基线上还是 放在字母基线下方。</dd> <dt><code>under</code></dt> <dd>强制下划线的位置为字母基线的下方,在这个位置,下划线不会穿过任何字母,这样能确保数学方程式或者化学式的下标不会被下划线阻挡。</dd> <dt><code>left</code></dt> <dd>在垂直排版模式下,使下划线的位置在文字的左侧,在水平排版模式下,和 <code>under</code> 相同。</dd> <dt><code>right</code></dt> <dd>在垂直排版模式下,使下划线的位置在文字的右侧,在水平排版模式下,和 <code>under</code> 相同。</dd> <dt><code>auto-pos</code> {{non-standard_inline}}</dt> <dd><code>auto</code>的同义词 ,应使用 <code>auto</code>。</dd> <dt><code>above</code> {{non-standard_inline}}</dt> <dd>强制下划线放置于文本上面。当使用东亚文字时,此效果和使用 <code>auto</code> 相同。</dd> <dt><code>below</code> {{non-standard_inline}}</dt> <dd>强制下划线放置于文本下面。当使用字母文字的时候,此效果和使用 <code>auto</code> 相同。</dd> </dl> <h3 id="正式语法">正式语法</h3> <pre class="syntaxbox">{{csssyntax}}</pre> <h2 id="示例">示例</h2> <p>由于 <code>text-underline-position</code> 属性可以继承,且无法用 {{cssxref("text-decoration")}} 简写属性重置,所以应当在全局级别设置其值。比如,<code>under</code> 值对一篇包括大量使用下标的数学或者化学公式的文档是非常有用的。</p> <pre class="brush: css">:root { text-underline-position: under; }</pre> <h2 id="规范">规范</h2> <table class="standard-table"> <thead> <tr> <th scope="col">说明</th> <th scope="col">状态</th> <th scope="col">说明</th> </tr> </thead> <tbody> <tr> <td>{{SpecName('CSS3 Text Decoration', '#text-underline-position-property', 'text-underline-position')}}</td> <td>{{Spec2('CSS3 Text Decoration')}}</td> <td>初始定义</td> </tr> </tbody> </table> <h2 id="浏览器兼容性">浏览器兼容性</h2> <p>{{Compat("css.properties.text-underline-position")}}</p> <h2 id="参阅">参阅</h2> <ul> <li>{{cssxref("text-decoration")}} 属性是大多数作为设置 text-decoration 属性的简写形式,包括 {{cssxref("text-decoration-line")}}, {{cssxref("text-decoration-color")}}, 和{{cssxref("text-decoration-style")}}。但是,text-decoration 不会设置 <code>text-underline-position</code>。</li> <li>Microsoft <a href="http://msdn.microsoft.com/en-us/library/ie/ms531176%28v=vs.85%29.aspx">non-standard values documentation</a></li> </ul>