how to align two textfields? - html

I have an HTML code as follows
<body>
Hello UserName:<input tyep="text"/><br/>
Pass:<input type="text"/>
</body>
I want the two text fields should be aligned in such a way that their left borders should start from the same positions of two lines.Because as it is if I runs the two text fields starts exactly after their labels ends, which I don't want as it looks odd.
How would I do that?

Take a look at this example with Chrome Developer Tools or Firebug.
HTML:
<div class="main">
<div class="field">
<label for="n">Name</label>
<input type="text" name="n" />
</div>
<div class="field">
<label for="ln">Surnemt</label>
<input type="text" name="ln" />
</div>
<div class="field">
<label for="a">Bithplace</label>
<input type="text" name="a" />
</div>
</div>
CSS:
body {font-size:14px;}
label {float:left; padding-right:10px;}
.field {clear:both; text-align:right; line-height:25px;}
.main {float:left;}

Related

How to format HTML with CSS for column layout

I'm trying to do some simple HTML and CSS to get a page to layout something like the image below, but I'm way out of my element and not even sure how to get it started. Right now, my biggest problem is I can't get the Client Birth Date, and Spouse First Name to appear on its own line. I feel like I could add divs, but then I'd probably have divs everywhere (I'm assuming that's a bad thing.)
Here's a JSFiddle of what I have started.
<div>
<label for="WebName">Name</label>
<input type="text" id="WebName" />
</div>
<div>
<label for="WebEmail">Email</label>
<input type="text" id="WebEmail" />
</div>
<div>
<label for="WebPhone">Phone</label>
<input type="text" id="WebPhone" />
</div>
<hr />
<div style="border: 1px solid black; overflow: hidden;">
<!-- left -->
<div style="width: 500px; float:left; border: 1px solid red;">
<label for="ClientFirstName">Client First Name*</label>
<input type="text" id="ClientFirstName" />
<label for="ClientBirthDate">Client Birth Date</label>
<input type="text" id="ClientBirthDate" />
</div>
<!-- right -->
<div style="float:left; width: 500px; border: 1px solid green;">
<label for="ClientLastName">Client Last Name*</label>
<input type="text" id="ClientLastName" />
<label for="ClientAge">Client Age</label>
<input type="text" id="ClientAge" />
</div>
</div>
<hr />
<div>
<label for="AppointmentDate">Appointment Date</label>
<input type="text" id="AppointmentDate" />
<label for="Goals">Goals</label>
<textarea id="Goals" rows="4" cols="80">
</textarea>
</div>
I would add divs in those specific cases. Form elements can be messy when it comes to layout. I've found that wrapping a label + input inside a div is the best practice here. And since you've already done that in the first section you might as well follow the pattern.
<div class="inputWraper">
<label for="thisInputName">Some Text</label>
<input type="text" name="thisInputName" value="" placeholder="What displays />
</div>
You could technically also wrap everything in the label instead of a div. This has some pros and cons mostly in that it makes everything clickable and adds focus. It's especially good for checkboxes and radio buttons as the hit area is bigger.
<label for="thisInputName">
<span>Your label text</span>
<input type="text" name="thisInputName" value="" placeholder="What displays />
</label>

CSS: Why is this label taking up all the available space

The given example is probably a bit bigger than required but I could not figure out in hours where the problem lies, so I am posting it. You just have to look into the label #problematic and around it (Line number 9 in the JSFiddle).
The problem with it is that it takes up all the space left by the adjacent label. The question is why? And what to do about it?
I had worked out this example (with the help of some SO community) to make the layout before incorporating the complex content. It works perfectly in the example. But it behaves weirdly in my code.
Here is the JSFiddle.
CODE:-
<form action="http://localhost/moodle/mod/quiz/processattempt.php" method="post" enctype="multipart/form-data" accept-charset="utf-8" id="responseform">
<div>
<!-- ------------------------------------------------- -->
<div style="display:table;">
<div style="display:table-row; background-color:#e8c277;">
<label id="problematic" style="display:table-cell; padding:10px; border-width:1px;border-color:blue;border-style:solid;">True</label>
<label style="display:table-cell; padding:10px;border-width:1px;border-color:red;border-style:solid;"><span style="white-space:nowrap;">False</span></label>
<span style="display:table-cell;"></span>
</div>
<!-- ------------------------------------------------- -->
<div class="que multichoice deferredfeedback notyetanswered" id="q13">
<div>
<div class="formulation">
<h4 class="accesshide">Question text</h4>
<input type="hidden" name="q36:13_:sequencecheck" value="1" />
<div class="ablock" style="display:table-row;">
<span style="display:table-cell; text-align:center;">
<input type="radio" name="q36:13_answer" value="0" id="q36:13_answer0" />
</span>
<span style="display:table-cell; text-align:center;">
<input type="radio" name="q36:13_answer" value="1" id="q36:13_answer1" />
</span>
<label class="qtext" style="display:table-cell;">No individual country produces more than one-fourth of the world's sugar.
</label>
</div>
</div>
</div>
</div>
<div class="que multichoice deferredfeedback notyetanswered" id="q14">
<div>
<div class="formulation">
<h4 class="accesshide">Question text</h4>
<input type="hidden" name="q36:14_:sequencecheck" value="1" />
<div class="ablock" style="display:table-row;">
<span style="display:table-cell; text-align:center;">
<input type="radio" name="q36:14_answer" value="0" id="q36:14_answer0" />
</span>
<span style="display:table-cell; text-align:center;">
<input type="radio" name="q36:14_answer" value="1" id="q36:14_answer1" />
</span>
<label class="qtext" style="display:table-cell;">If Brazil produces less than 20% of the world's supply of any commodity listed in the table, Brazil is not the world's top exporter of than commodity.
</label>
</div>
</div>
</div>
</div>
<!-- ------------------------------------------------- -->
</div>
<!-- ------------------------------------------------- -->
<div class="submitbtns">
<input type="submit" name="next" value="Next" />
</div>
</div>
</form>
You can not have divs wrapping your table rows/cells. There were divs wrapping your second and third rows, causing them to be treated as if they were all in the first column.
See the fiddle below for an example of a working layout. Note: I deleted a lot of your divs. Your table structure has to be table:table-row:table-cell with no other divs wrapping the rows or cells. Removing the excess divs restored the proper layout.
JSFiddle

Bootstrap checkbox input align vertically

Using Bootstrap version 2.3.2, I have a form layout like the below image and since the checkbox has an inline label, there is an aligning issue.
Adding margin to input[type="checkbox"] only gives margin to the checkbox, not the inline label. How do I make it so the checkbox and its label vertically align to the text fields next to it?
Here is the
JS BIN if you are interested.
In your HTML add a class that will handle the checkbox margin:
<div class="container-fluid">
<div class="row-fluid">
<div class="span3">
<label>label 1</label>
<input type="text" />
</div>
<div class="span3">
<label>label 2</label>
<input type="text" />
</div>
<div class="span3 checkbox">
<input type="checkbox" />test description
</div>
</div>
</div>
and in your CSS:
input[type="checkbox"] {
// i just remove this part..
}
.checkbox {
margin: 30px 0 0 0;
}
Don't put the margin on the checkbox, but on the parent div.
Check this jsFiddle.
Hope this helps
Try to always use something like this:
<div class="span3">
<label for="checkbox" class="checkbox">
<input type="checkbox" id="checkbox" class="checkbox">test description
</label>
</div>
http://jsbin.com/itAdAWA/1/edit
How about putting a <label> before the checkbox like this? ..
<div class="container-fluid">
<div class="row-fluid">
<div class="span3">
<label>label 1</label>
<input type="text">
</div>
<div class="span3">
<label>label 2</label>
<input type="text">
</div>
<div class="span3">
<label>test</label>
<input type="checkbox">
</div>
</div>
</div>
Bootply: http://bootply.com/86998
I just solved this exact problem in bootstrap 3, by simply limiting the height of inline checkboxes to 12 pixels. They are by default 40px, I don't know why !
<div class="checkbox-inline">
<label>
<input type="checkbox" checked="checked" />
<span>My correctly aligned check-box</span>
</label>
</div>
add this in your css file (I personally have a css file named bootstrap-custom.css):
/*
Checkboxes in inline forms are misaligned because for an unknow reason they inherit a height of 40px !
This selector limit the height of inline checkboxes to 12px which is the perfect value to align them to
the other widgets in an inline form.
*/
.radio-inline, .checkbox-inline {
max-height: 12px;
}
Not ideal solution but change your code to ...
<div class="span5">
<input type="checkbox">test description</input>
</div>
and set the margin-top on that. I will result as you want - better.
Bootstrap v5+
<!-- mt-md-4 pt-md-3 this apply margin and padding only for desktop -->
<div class="col-md-3 mb-3 md-mt-4 md-pt-3">
<input class="form-check-input" type="checkbox" value="" id="flexCheckDefault">
<label class="form-check-label" for="flexCheckDefault">
Default checkbox
</label>
</div>

Bootstrap alignment inputs

I would like to align vertically all my inputs, how can I do it ?
Cause label can be very long and I want that alignemnt still perfect.
CSS
.span6{
overflow:hidden;display:inline;
}
.span6 label, .span6 input {
display:inline-block;
}
.span6 input {
width:70%;
margin-left:3%;
}
HTML
<div class="row-fluid">
<form class="form well">
<div class="row-fluid">
<div class="control-group span6">
<label for="first-name">Company</label>
<input class="first-name" type="text" class="input-block-level" />
</div>
<div class="control-group span6">
<label for="last-name">Title</label>
<input class="last-name" type="text" class="input-block-level" />
</div>
<div class="control-group span6">
<label for="last-name">Country</label>
<input class="last-name" type="text" class="input-block-level" />
</div>
</div>
</div>
</div>
JSFIDDLE
http://jsfiddle.net/kY5LL/154/
You should probably read a bit more the Bootstrap documentation, there is built-in styles for aligning forms horizontally and vertically.
I modified your code to use the horizontal style (.form-horizontal).
http://jsfiddle.net/LeBen/kY5LL/156/

HTML how to place a form in 2 divs/columns?

I have 1 form and I would like to place it in 2 divs, so that the following:
<div style="float:left; position:relative; margin-right:40px">
<form id="testForm2">
</form>
</div>
<div position:relative">
<form id="testForm2">
</form>
</div>
would be turned into something like this:
<div style="float:left; position:relative; margin-right:40px">
<form id="testForm2">
</div>
<div position:relative">
</form>
</div>
See the fiddle. Any ideas?
Thanks!
What you want, is to put the form around both divs like so:
<form id="testForm2">
<div style="float:left; position:relative; margin-right:40px">
</div>
<div style="position:relative">
</div>
</form>
Here's an updated version of your jsFiddle.
Edit
Also, your second div's style is incorrect. It's fixed now in my example.
The markup in your jsFiddle file required some tidying up. This is what i would go with, trying to minimize your code somewhat:
<div class="post_edit_modeling">
<div class="tab_trash">
<div id="prof_picture">
<form id="testForm2">
<fieldset id="left">
<legend>Sex:</legend>
<div>
<label>
<input type="radio" name="sex" id="genderMale" value="male" />
Male
</label>
</div>
<div>
<label>
<input type="radio" name="sex" id="genderFemale" value="female" />
Female
</label>
</div>
<div>
<label>Weight</label>
<input id="weightpounds" type="text" name="weightpounds"/>
</div>
<div>
<label>Bust</label>
<input id="bust" type="text" name="bust"/>
</div>
</fieldset>
<fieldset id="right">
<div>
<label>Cup</label>
<input id="cup" type="text" name="cup"/>
</div>
<div>
<label>Waist</label>
<input id="waist" type="text" name="waist"/>
</div>
<div>
<label>Hips</label>
<input id="hips" type="text" name="hips"/>
</div>
<div>
<label>Hair Color</label>
<select name="haircolor">
<option value="1">White</option>
<option value="2">Black</option>
<option value="3">Yellow</option>
<option value="4">Blue</option>
</select>
</div>
<div>
<label>Dress Size</label>
<input id="dress" type="text" name="dress"/>
</div>
</fieldset>
<fieldset>
<div>
<input type="button" name="btnUpdate" id="btnUpdate" value="Update" />
</div>
</fieldset>
</form>
</div>
</div>
</div>
CSS:
form div {float: left; margin-bottom: 15px;}
fieldset { float: left; width: 200px; border: 0; padding: 0; margin: 0;}
#left { }
#right { margin-right: 0; }
label {float: left;}
input {clear: both;; float: left}
Ive updated your jsFiddle file. Here.
Can you not just make the two divs live inside the form? Like this:
<form id="testForm2">
<div style="float:left; position:relative; margin-right:40px">
Form Content Here
</div>
<div position:relative">
Form Content Here
</div>
</form>
If the form is affecting your page layout, make sure that you set the form style to display:inline;!
As Drackir and joe_coolish said, you don't need to nest your form tags that way.
Typically I always open the entire content block with the form tag, totally isolated from the other content. There's absolutely no harm in doing things this way. ANything including <h1> and entire layouts can be nested in a form, as long as you know that every input within it will belong to that form.
<form>
<!-- tons of content here including layout -->
</form>
Can't you just put the 2 DIV's inside the FORM tags? Something like:
<form>
<div id="one">
...
</div>
<div id="two">
</div>
</form>
edit: Seems I'm a little too late :)
Just move your <div> tags within the <form>...
<form id="testForm2">
<div style="float:left; position:relative; margin-right:40px">
... left side ...
</div>
<div position:relative">
... right side ...
</div>
</form>
what about
<form id="testForm2">
<div style="float:left; position:relative; margin-right:40px">
</div>
<div position:relative">
</div>
</form>