Switching font-family while retaining width
Is it possible to keep the exact width of a <span>
while changing the font-family
of the text inside ? I am thinking about balancing th开发者_运维百科is width with font-size
or font-size-adjust
because letter-spacing
will not render gracefully.
I chose deliberately two very different typefaces: Times and Verdana.
Rollover the demo: http://jsbin.com/ahiba4/20
It is possible, but only using JavaScript.
- Store the container's width in a variable
- Change the font in the container
Set the font size so the container matches the previous width again using one of the methods shown in these questions:
- How to auto resize text in fixed DIV according to the text's length?
- JavaScript Scale Text to Fit in Fixed Div (this is the best one IMO)
精彩评论