2023-12-13 05:00:04

只在CSS上标?

我怎么能得到上标做,只有在CSS?

我有一个样式表,我用上标字符标记外部链接,但我很难让字符正确对齐。

我目前拥有的是这样的:

a.external:after {
  font-size: 50%;
  vertical-align: top;
  content: "+";
}

但这并不奏效。

当然,我会使用<sup>-标签,只有当内容允许HTML…


当前回答

CSS属性font-variant-position正在考虑中,可能最终会成为这个问题的答案。不过,截至2017年初,只有Firefox支持它。

.super {
    font-variant-position: super;
}

看到MDN。

其他回答

http://htmldog.com/articles/superscript/本质上:

position: relative;
bottom: 0.5em;
font-size: 0.8em;

据我所知,在实践中效果很好。

下面摘自Mozilla Firefox的内部html.css:

sup {
  vertical-align: super;
  font-size: smaller;
  line-height: normal;
}

所以,在你的情况下,它会是这样的:

.superscript {
  vertical-align: super;
  font-size: smaller;
  line-height: normal;
}

我不确定这是否相关,但我已经解决了我的问题&sup2;HTML实体,因为我无法在<label>标签内添加任何其他HTML标签。所以这个想法是使用ASCII码而不是css或HTML标签。

.superscript {
  position: relative;
  top: 5px;
  font-size: 90%;
  vertical-align: super;
}

try

.aftersup {
 font-size: 1em;
 margin: left;
 vertical-align: .7em;
}

或者简单的“after”

.after {
 font-size: 1em;
 margin: left;
 vertical-align: .7em;
}

”。。外部:after”可以简化

or

.after {
 font-size: 50%;
 margin: left;
 vertical-align: .7em;
}

使用“字体大小50%”-什么大小的50% ?这可能不会很好地工作,如果不使用在一些标签定义文本大小之前的上标…

如果你使用"font-size: 1em;",那么字体大小是确定的,没有引用定义链接文本大小的标签,除非链接文本设置为100%,上标是100%的50%。

使用“font-size: 1em;”实际上设置字体大小基线。

如果你想要上标字体小于链接文本,请将“垂直对齐”设置为较小的大小

设置“vertical-align”大小与字体大小相同,如果你想让上标字体与链接文本大小相同

要与链接文本对齐,您需要设置与链接文本相同的“margin”(左,中,右,对齐)。

.text {
  font-size: 1em;
  margin: left;
}
.aftersup {
  font-size: 1em;
  margin: left;
  vertical-align: .7em;
}

它应该是类似下面的例子链接与上标

<p class="text"><a href="url">https://stackoverflow.com/questions/501671/superscript-in-css-only</a><aftersup>+</aftersup></p>

or

<p class="text"><a href="url">https://stackoverflow.com/questions/501671/superscript-in-css-only</a><aftersup>You got this</aftersup></p>

or

<a href="url">https://stackoverflow.com/questions/501671/superscript-in-css-only</a><aftersup>+</aftersup>

or

<a href="url">https://stackoverflow.com/questions/501671/superscript-in-css-only<aftersup>You got this</aftersup>

就像在……

只在CSS上标?+

or

只在CSS上标?你懂的