Question

Let's say I have something like this:

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

I want to have the "(8)" as a superscript how?

Note: I know that you can do it with:

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

But I want to do it without that...

Was it helpful?

Solution

You can inject a seperate style with the ::after pseudo class.

CSS

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

HTML

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

Using the attr() property, you can dynamically change the superscript value based on the data-superscript attribute.

Note that this is CSS3, and it's not compatible with all browsers.

JSFiddle

OTHER TIPS

Use the unicode superscript 8 character, and make sure you're document is valid as UTF-8:

<input type="button" value="2⁸" />
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top