I have a html form that is basically vertical but i really have no idea how to make two text fields on the same line. For example the following form below i want the First and Last name on the same line rather then one below the other.
<form action="/users" method="post"><div style="margin:0;padding:0">
<div>
<label for="username">First Name</label>
<input id="user_first_name" name="user[first_name]" size="30" type="text" />
</div>
<div>
<label for="name">Last Name</label>
<input id="user_last_name" name="user[last_name]" size="30" type="text" />
</div>
<div>
<label for="email">Email</label>
<input id="user_email" name="user[email]" size="30" type="text" />
</div>
<div>
<label for="pass1">Password</label>
<input id="user_password" name="user[password]" size="30" type="password" />
</div>
<div>
<label for="pass2">Confirm Password</label>
<input id="user_password_confirmation" name="user[password_confirmation]" size="30" type="password" />
</div>
Put
style="float:left"
on each of your divs:Example:
To put an element on new line, put this div below it:
Of course, you can also create classes in the CSS file:
And then your html should look like this:
To put an element on new line, put this div below it:
More Info:
I would go with Larry K's solution, but you can also set the display to inline-block if you want the benefits of both block and inline elements.
You can do this in the div tag by inserting:
Or in a CSS stylesheet with this method:
Hope it helps, but as earlier mentioned, I would personally go for Larry K's solution ;-)
You should put the input for the last name into the same div where you have the first name.
Then, in your CSS give your #user_first_name and #user_last_name height and float them both to the left. For example:
For the sake of bandwidth saving, we shouldn't include
<div>
for each of<label>
and<input>
pairThis solution may serve you better and may increase readability
The css for above form would be
I believe the output would be as following:
The default display style for a div is "block." This means that each new div will be under the prior one.
You can:
Override the flow style by using float as @Sarfraz suggests.
or
Change your html to use something other than divs for elements you want on the same line. I suggest that you just leave out the divs for the "last_name" field