Here's an excerpt from a fairly standard Rails form:
<p>
<%= f.label :from_station %> <%= f.text_field :from_station %>
</p>
<p>
<%= f.label :to_station %> <%= f.text_field :to_station %>
</p>
By default, this renders like this:
alt text http://img412.imageshack.us/img412/127/picture6u.png
This doesn't look great since the text fields don't line up. What's the easiest way to make the form look more like this:
alt text http://img193.imageshack.us/img193/746/picture7shk.png
I've tried setting the width
style property on the <label>
s, but this property doesn't seem to do anything.
We specify the margin-bottom of our <div> element. Then, we set the display of the <label> element to "inline-block" and give a fixed width. After that, set the text-align property to "right", and the labels will be aligned with the inputs on the right side.
Using float and overflow attributes: Make a label and style it with float attribute. Now set the label float(position) left or right according to your requirement. This will align your label accordingly. Overflow property for input is used here to clip the overflow part and show the rest.
HTML | <input> align Attribute left: It sets the alignment of image to the left. it is a default value. right: It sets the alignment of image to the right. middle: It sets the alignment of image to the middle.
I think this is more of a CSS question;
Labels by default aren't a block level element and so won't accept a width. Try setting this CSS:
label{
width: 4em;
float: left;
text-align: right;
margin-right: 0.5em;
display: block
}
Hope that helps!
You can use a <table>
where each label is in column 1 and each textfield is in column 2.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With