Accessibility

CSS Advisor

Keep consistent line spacing with sup and sub

by Brian Tapley on July 25, 2007
Edited by: mzaharia@adobe.com on November 24, 2009
Avg Rating 4.3 (12)   |   Log in to rate post.

Tagged with Explorer 6.0 , Explorer 7.0 , Safari 1.0 , Explorer for Mac , Safari 3 , Firefox 1.0 , Explorer 5.0 , Safari 2.0 , Opera 7.x , Position , vertical-align , line-spacing , Firefox 1.5 , Explorer 5.5 , Width/Height , Opera 8.5

Problem

Adding a <sup> or <sub> tag can throw off the line-spacing of a text block.

Solution

Use CSS to override the default browser style.

Detailed description

The selectors

<style type="text/css">
sup,
sub {
height: 0;
line-height: 1;
vertical-align: baseline;
_vertical-align: bottom;
position: relative;

}

sup {
bottom: 1ex;
}

sub {
top: .5ex;
}
</style>

Note that before version 7, IE treated vertical-align uniquely among other browsers. Using this approach, I need the underscore hack for IE 6 and below.

The markup

<sup>...</sup>
<sub>...</sub>

Before


After


before.gif
after.gif




Text ID: KEEP_CONSISTENT_LINE_SPACING_WITH_SUP_AND_SUB



Comments (4)

To add a comment, please Log in.




Thank you, it works

It worked, thanks Adobe

Superb Solution

A quick search on google and I found the solution. Great job!

seconded...

this was very helpful.

it works!

I found this via a search on google, and it helped me solve a problem I was having with some superscript text.  I figured the least I could do is say thanks.  So... thanks!





CSS Advisor home
Submit a post

rss

CSS ADVISOR RSS FEEDS
Recent: POSTS | COMMENTS | EDITS


Browsers
Internet Explorer (45)
Mozilla/Firefox (16)
Opera (7)
Safari (13)
CSS Properties
Background (6)
Border (3)
Color (1)
Float (15)
Font (1)
Margin (6)
Padding (4)
Position (15)
Text (13)
Width/Height (9)