html - 使用 <sub> 标签并保持行高

标签 html css

我有一段带有一些下标和上标标签的长文本。示例:

<div>hello <sub>world</sub>, how are you? Translated as logical aggregates or associative compounds, these characters have been interpreted as combining two or more pictographic or ideographic characters to suggest a third meaning.</div>

实例在 http://jsfiddle.net/BzqFb/

现在我可以看到有文本的文本行比没有文本的文本行宽。有什么办法可以更改标签样式 css 并使所有文本行的高度完全相同?

是否有某种文本可以改变 HTML 文本中的行高?

编辑:我想要下标行为,而不仅仅是小文本。我可以使行高变大,以便下标文本适合该行,但带有下标文本的行仍然比没有下标文本的行宽。

最佳答案

Is there any way how I can change tag style css and have all lines of text with exactly same height

为什么你不使用 <small>元素?它使文本与相同的行高垂直对齐:

<div class="container">hello <small>world</small>, how are you? ...</div>

Fiddle Demo

根据原始发帖人的评论,您可以使用 position: relative;为下标元素设置一个 top0.2em保留整个文本的行高:

sub {
    vertical-align: text-bottom; /* <-- Reset the user agent stylesheet   */
    position: relative;          /* <-- Set position to the element       */
    top: .2em;                   /* <-- Move the <sub> element down a bit */
}

UPDATED FIDDLE

关于html - 使用 <sub> 标签并保持行高,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21679699/

相关文章:

javascript - 为什么单击时未调用 javascript 代码

javascript - 单击提交按钮时的 HTML 表单验证

javascript - angularjs 在应用程序初始化后注入(inject)模块

javascript - Bootstrap 4 pills 点击内容显示在下方和/或不显示

html - 如何使图像轮播工作?

javascript - 如何在 iOS 上自动播放 HTML5 <video> 和 <audio> 标签?

html - 这是一种纠正绝对 iframe 的 Internet Explorer View 的方法吗?

css - 对用户 css 的危险

Javascript - 内容中带有列表的选项卡

css - 将 DIV 放置在两个较低的 DIV 之间和上方