html - 居中文本忽略上标
问题描述
我有一个居中对齐的文本表。但有些文本包含上标。有没有办法让文本对齐并忽略上标?
例如,在这段代码中,如何使 2 在 1 的正下方对齐。
td {
width: 200px;
text-align: center;
}
<table>
<tr>
<td>1</td>
</tr>
<tr>
<td>2<sup>hello</sup></td>
</tr>
</table>
解决方案
您可以将文本包装在一个跨度中,并绝对定位上标文本:
td {
width: 200px;
text-align: center;
}
td>span {
position: relative;
}
span>sup {
position: absolute;
/* play with the below to line up your sup properly */
top: -0.4em;
left: 100%;
margin-left:0.1em;
}
<table>
<tr>
<td>1</td>
</tr>
<tr>
<td><span>2<sup>hello</sup></span></td>
</tr>
</table>
推荐阅读
- python - Pandas - 多线图
- c - 如何使用 printf 将指针值格式化为 0x0000...?
- hive - 循环出现在 Hive 表 (Hive-QL) 中每一行中的值
- php - 使用PHP根据函数中的变量显示动态图像
- python - 如何修改获取股票价格每日支点(高点/低点)的循环以获取每周?
- php - 无法通过社交登录对用户进行身份验证
- python - 如何在空文件上加载 json.load(filename)?
- azure - Microsoft Teams + Azure 机器人:间歇性错误 403“机器人不是对话名单的一部分”
- scala - 将 csv 读入带有时间列的 hdfs 不起作用
- android - Android Studio - 整个项目中的全局变量?