views:

131

answers:

3
+1  Q: 

Right Align Input

I must be brain dead. I'm having a hell of a time right aligning numbers in a input field.

.number {
     text-align: right;
}

<input name="price" type="text" class="number" />

has no effect.

I need to use an input field since I refer to the value in JavaScript and I'm using it both for input and display.

Thanks

+3  A: 

Yeah - text-align: right should work.

Are you sure there isn't another style or something that's overriding it?

(If you don't have it already, I'd recommend the FireBug plugin for Firefox: right-click the element in question and select "Inspect Element" - that'll tell you every style that's actually being applied, and what's overridden what.)

teedyay
teedyay: Good advice re: FireBug.
David Andres
+2  A: 

It could be that you have a more specific selector that overrides the text-align property of .number

To make your selector more specific, specify the element type...

input.number {
   text-align: right;
}

You may have to get even more specific than that, such as...

#formId input.number { }
Josh Stodola
thank you all, I am brain dead. It would help if I put the class on the right input field.
sdfor
+2  A: 

If you still can't get that class to override styles coming in from elsewhere, you may also want to try

text-align: right !important;

sparkey0
good idea! I've got it working now.You guys are great
sdfor
one other thinginput[type=text] { text-align: right;}.left { text-align: left !important;}input[type=text] works fine. I read that it won't work in IE but it seems to for me in IE7. (I have a captive audience and don't need to support ie6). And since the vast majority of my fields are numberic I make that the default and added the left class for the few alphanum fields. the left class would not override the the right style even when placed afterwards unless I used !important; as you suggested.I wonder why the last style didn't override the first?
sdfor