简体   繁体   English

CSS / HTML-如何在 <input type=“button”/> ?

[英]CSS/HTML - How can I write superscript in a <input type=“button”/>?

Let's say I have something like this: 假设我有这样的事情:

    <input type="button" value="2(8)">

I want to have the "(8)" as a superscript how? 我想将“(8)”作为上标如何?

Note: I know that you can do it with: 注意:我知道您可以使用以下方法做到这一点:

     <button>2<sup>8</sup></button>

But I want to do it without that... 但是我想没有那个...

You can inject a seperate style with the ::after pseudo class. 您可以使用::after伪类注入单独的样式。

CSS CSS

button::after {
    content: attr(data-superscript);
    vertical-align: super;
}

HTML HTML

<button data-superscript="8">2</button>

Using the attr() property, you can dynamically change the superscript value based on the data-superscript attribute. 使用attr()属性,您可以基于data-superscript属性动态更改上标值。

Note that this is CSS3, and it's not compatible with all browsers. 请注意,这是CSS3, 并非与所有浏览器都兼容。

JSFiddle 的jsfiddle

使用Unicode上标8个字符,并确保您的文档作为UTF-8有效:

<input type="button" value="2⁸" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM