fixed-width (monospaced) fonts - I'd like a script that somehow can
align it based on the width of each letter in a standard Arialish
font.
Simply put, this is impossible.
With a fixed-width font every character has the same width, hence the name, fixed width.
With other fonts this is not the case. For example, you can plainly see that the i
is much narrower than the M
.
You can't know which font the user uses, even if you specify something like font-family: Arial
this may not always work, different systems (OSX, X11, etc.) use different fonts, and some users also override font website's settings, etc.
And even if you knew for 100% certainty which font the user uses, it would be pretty much impossible to align everything to be pixel-perfect.
So, you have two options: either use a fixed width font ("Consolas" is a standard Windows font which looks fairly good), or use a different layout.
What you probably want is something like this:
<style>
span { display: block; width: 20em;}
</style>
<span>Some text</span>
<span>Hello, world!</span>
<span>A swallow could not carry a coconut</span>
Here, every <span>
is the same width (20em
) regardless of the amount of text it contains.
Using spaces to align stuff is almost always a bad idea. Using CSS is not only much cleaner, it's also a lot easier.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…