Html 在某些文本下划线,并将下标居中

Html 在某些文本下划线,并将下标居中,html,css,Html,Css,请参阅所附图片。如何使用CSS实现这样的下划线效果?这需要进行一些微调,但类似的操作可能会奏效: <p>Your <span class="toUnderline">test <span class="subscript">3</span> some</span> more text.</p>| <style> .subscript { line-height:-15px; letter-s


请参阅所附图片。如何使用CSS实现这样的下划线效果?

这需要进行一些微调,但类似的操作可能会奏效:

<p>Your <span class="toUnderline">test <span class="subscript">3</span> some</span> more text.</p>|
<style>
   .subscript {
    line-height:-15px;
    letter-spacing:-5px;
    text-decoration:none;    
    }
     .toUnderline{
    text-decoration:underline;
   }
</style>
您的测试3需要更多的文本。

| .下标{ 线高:-15px; 字母间距:-5px; 文字装饰:无; } toUnderline先生{ 文字装饰:下划线; }
这需要一些微调,但类似的方法可能会奏效:

<p>Your <span class="toUnderline">test <span class="subscript">3</span> some</span> more text.</p>|
<style>
   .subscript {
    line-height:-15px;
    letter-spacing:-5px;
    text-decoration:none;    
    }
     .toUnderline{
    text-decoration:underline;
   }
</style>
您的测试3需要更多的文本。

| .下标{ 线高:-15px; 字母间距:-5px; 文字装饰:无; } toUnderline先生{ 文字装饰:下划线; }
我相信这正是您想要的:

HTML:

<span class="underlined">example text<hr/>#</span>
.underlined {
    display:inline-block;
    vertical-align:text-top;
    text-align:center;
}
.underlined hr {
    border:none;
    border-top:1px solid black;
    margin:0;
}

span显示为
内联块
元素,因此它允许在
span
中使用诸如

之类的换行元素。使用它,您只需在文本本身和下标之间放置一个

,就可以得到所需的结果。需要使用
垂直对齐
,以使文本本身适合文本的常规流程,并将下标推到文本下方


但请注意,这将中断文本的流动。我不知道你想用它做什么,但我认为可能有另一种方法可以得到你想要的结果,而不必使用它。

我相信这正是你想要的:

HTML:

<span class="underlined">example text<hr/>#</span>
.underlined {
    display:inline-block;
    vertical-align:text-top;
    text-align:center;
}
.underlined hr {
    border:none;
    border-top:1px solid black;
    margin:0;
}

span显示为
内联块
元素,因此它允许在
span
中使用诸如

之类的换行元素。使用它,您只需在文本本身和下标之间放置一个

,就可以得到所需的结果。需要使用
垂直对齐
,以使文本本身适合文本的常规流程,并将下标推到文本下方


但请注意,这将中断文本的流动。我不知道您想用它做什么,但我认为可能有另一种方法可以获得您想要的结果,而不必使用它。

我将使用绝对定位和百分比,让您可以灵活地将其放置在类中并在不调整的情况下重用

按如下方式构造HTML:

<p>This is a simple statment with some <span class="underline">underlined text<span>3</span></span>and a number under it. But it s a bit longer to mix it up.</p>
<p>This is a simple statment with some <span class="underline">underlined text<span>3</span></span>and a number under it. But it s a bit longer to mix it up. But it s a bit longer to mix it up.But it s a bit longer to mix it up.But it s a bit longer to mix it up.But it s a bit longer to mix it up.But it s a bit longer to mix it up.</p>
另一种CSS方法是:

p {
    font-size:1em;
    line-height:2.2em;
}
p span {
    position:relative;
    width:auto;
    text-decoration:underline;
}
p span span {
    position:absolute;
    width:100%;
    top:.5em;
    left:50%;
    text-decoration:none;
}

我将使用绝对定位和百分比来为您提供将其放置在类中的灵活性,并且无需调整即可重用

按如下方式构造HTML:

<p>This is a simple statment with some <span class="underline">underlined text<span>3</span></span>and a number under it. But it s a bit longer to mix it up.</p>
<p>This is a simple statment with some <span class="underline">underlined text<span>3</span></span>and a number under it. But it s a bit longer to mix it up. But it s a bit longer to mix it up.But it s a bit longer to mix it up.But it s a bit longer to mix it up.But it s a bit longer to mix it up.But it s a bit longer to mix it up.</p>
另一种CSS方法是:

p {
    font-size:1em;
    line-height:2.2em;
}
p span {
    position:relative;
    width:auto;
    text-decoration:underline;
}
p span span {
    position:absolute;
    width:100%;
    top:.5em;
    left:50%;
    text-decoration:none;
}

不是答案,但你为什么要用这个?我相信一定有其他方法来实现你的目标。这不是一个下标。到目前为止,你应该表现出你最大的努力,而不是期望别人帮你解决你(含糊不清的)问题。这不是答案,但你为什么要用这个?我相信一定有其他方法来实现你的目标。这不是一个下标。您应该尽最大努力,而不是期望其他人为您解决(模糊指定的)问题。您甚至可能希望使用jquery动态添加span.subscript,我会使用Joetje50è的答案你甚至可能想用jquery动态添加span.subscript,并将其插入每个span.toUnderline的正中间以保持一致。我会使用Joetje50è的答案