tags:

views:

316

answers:

4

This may be a dumb noob question, but I can't figure out how to make my text area use a monospaced font.

+2  A: 

If I'm understanding properly, it should already inherit default user-agent styles, but if you want to explicitly, just specify a font-family ( styles jacked from Stackoverflow stylesheet )

textarea {
  border:1px solid #999999;
  font-family:Consolas,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,Bitstream Vera Sans Mono,Courier New, monospace;
}

Specify the more specific (monospace-specific) font families first, and if the user agent doesn't have that available it will keep trying them until the end, in which case it would default to the default user agent font family for that element, if any was specified.

meder
You might want to add a `monospace` to the end of that, to get the default fallback monospace font if none of the other ones specified exist.
Brian Campbell
ah missed that; my eye tricked me and I thought it was there.
meder
Ahhh. I had font-family: "monospace"; I bet it's the quotes which are messing it up.
Software Monkey
A: 

Just use a monospace font. For example for something like:

<textarea id="mytextarea"></textarea>

the css would be:

#mytextarea {
    font-family: monospace;
}

If you want to use a specific monospace font, you can but don't forget adding the generic 'monospace' at the end in case the user does not have your preferred font installed:

#mytextarea {
    font-family: 'DejaVu Sans Mono', monospace;
}
slebetman
+1  A: 

You can also use the standard generic font-family: monospace, but be careful -- there are some severe side effects (sadly) in Chrome, Safari and anything WebKit based.

see:

Jeff Atwood
+1 for the warnings about inconsistent browser defaults; luckily this application is for programmers exclusive (in our company) who can be expected to set their browser fonts according to their desires.
Software Monkey
A: 
textarea
{
font-family: monospace;
}

You may need to add an important if not working

textarea
{
font-family: monospace !important;
}
Gazzer