-3

  div  { 
    display: inline;

}
.sub1{
    vertical-align: sub;
    font-size:x-small;
}
    <div>H</div>
    <div class="sub1">2</div>
    <div>O</div>
Problem is the letter space between H, 2(subscript), 0 renders high and I wanna compact the letter spacing more.

I can't use letter-spacing less than 1 px as it is not effective.

James Z
  • 12,209
  • 10
  • 24
  • 44
Michael36
  • 150
  • 11

3 Answers3

1

Write in one div and only wrap 2 in span

div  { 
    display: inline;

}
.sub1{
    vertical-align: sub;
    font-size:x-small;
}
<div>
H<span class="sub1">2</span>O
</div>
Justinas
  • 41,402
  • 5
  • 66
  • 96
1

  div  { 
    letter-spacing:-0.05em;

}
sub {
    vertical-align: sub;
    font-size:x-small;
}
    <div>H<sub>2</sub>O</div>

You can use letter-spacing with a negative value to reduce letter spacing. I prefer to use em values because they are relative to font-size.

As others mentioned in their comments, it would be better to use <sub> instead of <span> for this purpose.

jono
  • 1,792
  • 17
  • 18
0

    div  { 
    display: block;
}
.sub1{
    vertical-align: sub;
    font-size:x-small;
}
<div>H<span class="sub1">2</span>O</div>
<div>CO<span class="sub1">2</span></div>
<div>SO<span class="sub1">4</span></div>

I have made some minor change with regards to styling and html content

Michael36
  • 150
  • 11