Aligning textboxes via HTML - html

Here is my code:
Classroom name: <input type="text" name="txtClassroomName" size="20"><br>
School name: <input type="text" name="txtSchoolName" size="20"><br>
School contact email address: <input type="text" name="txtSchoolEmail" size="20"><br>
School address: <input type="text" name="txtSchoolAddress" size="20"><br>
School telephone number: <input type="text" name="txtTelephoneNumber" size="20"><br>
As you can probably guess, this code displays some text and then has some textboxes after this text.
My question is this: I am wanting to align all the texboxes so that they are aligned. I have added spaces after the text, yet the textboxes just appear straight after the text, ignoring the spaces that I entered. What is the best, most effective way to do this? Maybe a table?
thanks

Normally you'd use css to do this for you. in your css file add:
label{
display:inline-block;
width:200px;
margin-right:30px;
text-align:right;
}
input{
}
fieldset{
border:none;
width:500px;
margin:0px auto;
}
Then in the html you would set the labels up next to the textboxes:
<fieldset>
<label for="txtClassroomName">Classroom name:</label><input type="text" name="txtClassroomName" size="20">
<label for="txtSchoolName">School name:</label><input type="text" name="txtSchoolName" size="20">
<label for="txtSchoolEmail">School contact email address:</label><input type="text" name="txtSchoolEmail" size="20">
<label for="txtSchoolEmail">School address:</label><input type="text" name="txtSchoolAddress" size="20">
<label for="txtSchoolEmail">School telephone number:</label><input type="text" name="txtTelephoneNumber" size="20">
</fieldset>
in the css file, the margin-right:30px; line tells it how far apart to put the label and textbox
setting the fieldset width essentially creates a box round it all and you can set it's width if you need to make any labels bigger.
Hope that helps.
Martyn

<table>
<tr><td><label for="txtClassroomName">Classroom name:</label>
<td><input type="text" name="txtClassroomName" id="txtClassroomName" size="20">
<tr><td><label for="txtSchoolName">School name:</label>
<input type="text" name="txtSchoolName" id="txtSchoolName" size="20"><br>
...
</table>
A table is the only way to make the columns aligned so that the first column occupies just the width it needs (the width of the longest label). Any other approach forces you to make a guess on the width, and the results will inevitably vary, and the code will not be robust (the width needs to be adjusted whenever the length of the longest label changes).

In HTML, continuous SPACEs are taken as a single space only. So you need HTML Special Character for the SPACE, that is
Classroom name: <input type="text" name="txtClassroomName" size="20"><br>
But, this is the dirty way. This is not the standard way to do so. Also, this doesn't sure that the textboxes will align same until you use some mono-space fonts.
So, you should consider either <TABLE> tag or CSS.

You can also make all the textboxes to appear one below the other in the center of your screen. It will look uniform.

Related

How to centrally align text boxes with each other?

I am trying to get these text boxes to align in a neat order with one another in order to actually look nice, however upon browser viewing they're scattered all over the place. Below is my textbox declaration:
Enter ISBN to update: <input type="text" name="isbn" placeholder="Enter ISBN..."> <br><br>
Title <input type="text" name="titleUpdate " placeholder="Enter Updated Title..."> <br><br>
Author <input type="text" name="authorUpdate" placeholder="Enter Updated Author..."> <br><br>
Genre <input type="text" name="genreUpdate" placeholder="Enter Updated Genre..."< <br><br>
Year Published <input type="text" name="yearUpdate" placeholder="Enter Updated Year..."<br><br>
<!--ISBN <input type="text" name="isbnUpdate" placeholder="First name"<br><br>-->
I feel as though I need to do some CSS magic however I'm not so sure as to what I need to do.
I think you are off to a good start. There are some errors in your HTML, a couple of the items have wrong closing tags. What you want to do is structure the markup a little to give you some control. Take for instance this markup:
<div class="field">
<label for="isbn">Enter ISBN to update:</label>
<input type="text" id="isbn" name="isbn" placeholder="Enter ISBN...">
</div>
<div class="field">
<label for="titleUpdate">Title</label>
<input type="text" id="titleUpdate" name="titleUpdate" placeholder="Enter Updated Title...">
</div>
<div class="field">
<label for="authorUpdate">Author</label>
<input type="text" id="authorUpdate" name="authorUpdate" placeholder="Enter Updated Author...">
</div>
<div class="field">
<label for="genreUpdate">Genre</label>
<input type="text" id="genreUpdate" name="genreUpdate" placeholder="Enter Updated Genre...">
</div>
<div class="field">
<label for="yearUpdate">Year Published</label>
<input type="text" id="yearUpdate" name="yearUpdate" placeholder="Enter Updated Year...">
</div>
Notice how we wrap the text for the text fields as labels. I grouped a label and input field together in its own . Once you have your HTML structure, we can adjust how it looks. For example, aligning all the labels to the left, and then align the boxes to right would "align in a neat order". One way of doing this by using this css:
.field {
margin-bottom:10px;
width:400px;
clear:both;
}
label {float:left;}
input[type=text] {float:right; width:200px;}
Take a look at this codepen as an example - https://codepen.io/anon/pen/vwmRbv

How to put text newar text at buttom op page

I am trying to put few form, near to each other at bottom of the page.
Try to do that with css, but nothing work.
This is the css:
#Dcustomer,#Dorder,#admin{
text-align:inline-block;
}
#Uadmin,#Uorder,#Ucustomer,#add
{
float:right;
vertical-align:10px;
}
This is example for the one of the form:
<form action="AdminControl.php" id="Uorder" method="POST">
<h3><b><u>Update Order</b></u> </h3><br>
Order Number: <input type="text" name="Onumber"><br><br>
Product Name: <input type="text" name="product_name"><br><br>
Customer Name: <input type="text" name="name"><br><br>
Customer Number: <input type="text" name="Cnumber"><br><br>
E-mail: <input type="text" name="email"><br><br>
Phone Number: <input type="text" name="phone"><br><br>
Quantity: <input type="text" name="quantity"><br><br>
<input type="submit" name="updateorder" value="Update">
</form>
Every screen may not be able to fit all in one line
So just float right or left every form (and reduce width if you want)
Link to example https://jsfiddle.net/vko4om7o/7/
form {
float: right;
vertical-align: 10px;
width: 25%;
}
Increase size of frame for better visibility
As I said in the comment you have syntax error in your css file.
You have to change text-align to display because text-align takes only left, right, center values.

Aligment of textbox in proportion to the text

How do I correct the following E-mail textbox alignment: ?
To make it look like this:
I know I can use tables, but how do I solve this problem without using tables? CSS maybe?
HTML:
<form action="" name="contactform" method="post">
<p></p>
First name: <input type="text" class="contact" name="contactfirstname" value="">
<br/>
Last name: <input type="text" class="contact" name="contactlastname" value="">
<br/>
E-mail: <input type="text" class="contact" name="email" value="">
<p></p>
The most minimalized version I could think of...
<form>
<label>First Name: <input type="text" name="firstName"></label>
<label>Last Name: <input type="text" name="lastName"></label>
<label>Email Address: <input type="email" name="emailAddress"></label>
</form>​
and
form {
width: 300px;
}
label {
display: block;
margin: 5px;
padding: 5px;
clear: both;
}
label input {
float: right;
}​
Since OP has edited his question to include his markup, I'll expand the answer.
Some Points of Improvement:
Remove the empty <p> element, and the <br/> elements. They have no value inside a form.
Use <label>s, that's what they were made for. You can wrap the label and the input inside of the <label> tag, or you can use <label for="element_id">Label</label><input id="element_id">.
Be consistent. If you decided to go with the <br /> type of format for singular tags, stick with it to the <input />s as well.
Use correct input types for specific inputs, there is type="email" for the email field, which will optionally have the browser check for you if it's a valid email address or not!.
Use CSS for design and layout, not <p>s and <br>s.
Good luck!
I'm assuming your HTML is something like:
<p>
Email
<input />
</p>
Change this to:
<p>
<label>Email</label>
<input />
</p>
This means you can then apply a fixed width to all your labels, making them consistent:
label
{
width:100px;
float:left;
}
http://jsfiddle.net/zvWqk/1/
Or as #Zeta has pointed out, nest your input inside the label, and float right. This will prevent you needing to apply a for attribute to your label.
http://jsfiddle.net/tt8gx/
Use CSS to make the labels display as block elements and have a fixed width. Display the inputs as block elements and float them left. Put a clear:left on the labels so they'll each be on a new line.

HTML form textarea problem

In my html form the word message is showing at the bottom-left of the textarea, How can I adjust it on the top-left of textarea? img - http://img641.imageshack.us/img641/415/htms.jpg
<form name="reg_form" method="post" action="home.php">
First Name:
<input type="text" name="f_name"/><br/> <br/>
Last Name:
<input type="text" name="l_name"/><br/> <br/>
Your Email:
<input type="text" name="new_email"/><br/> <br/>
Re-enter Email: <input type="text" name="check_email"/><br/> <br/>
Message: <textarea cols="30" rows="10" name="message"></textarea>
</form>
You'll need to use a <label> tag to put your, well, labels in. Then using some CSS you can align it to the top of the <textarea> using this:
label
{
display: inline;
vertical-align: top;
}
HTML:
<form>
<label>Message:</label>
<textarea></textarea>
</form>
There's a live example I made here.
In other news
Your technique of spacing the inputs using isn't the best. For one, different fonts have different space widths and secondly, it makes your code look rubbish. You can get around this by using <label>s with CSS inline-block. There's a working example here.

How Do I Format a HTML Form Without Using Tables

I know it's bad to use HTML Tables for everything... and that tables should be used only to present tabular data and not to achieve some style goal.
My question is, how do you make HTML forms with CSS so they look nice and aligned like when using tables?
Nick Rigby wrote an excellent article for A List Apart titled Prettier Accessible Forms
Uses fieldset, legend, label. Highly semantic.
Take a look at the code used in wufoo forms, they use ul's to format the forms and they look really good.
http://wufoo.com/gallery/templates/
You can try and strip the form as far back as possible and make do with the <label> and various form input elements as needed with a lean on the clear:left; attribute in the CSS.
This would make sure each line starts anew without having to wrap each line of the form in an extra <div> or <p> or even making a list out of it.
.formlabel{
clear:left;
display:block;
float:left;
margin:0 0 1em 0;
padding:0 0.5em 0 0;
text-align:right;
width:8em;
}
.forminput{
float:left;
margin:0 0.5em 0.5em 0;
}
.formwarning{
clear:left;
float:left;
margin:0 0.5em 1em 0;
}
Here's a sample HTML form showing examples of various input types and an extra validation message that you can hide or style as needed:
<fieldset><legend>Details</legend>
<label for="name" class="formlabel">Name</label>
<input id="name" name="name" type="text" class="forminput" />
<div class="formwarning">Validation error message</div>
<label for="dob_year" class="formlabel">DOB</label>
<div class="forminput">
<input id="dob_year" name="dob_year" type="text" size="4" /> /
<input id="dob_month" name="dob_month" type="text" size="2" /> /
<input id="dob_day" name="dob_day" type="text" size="2" />
</div>
<label class="formlabel">Sex</label>
<label for="female" class="forminput">Female</label>
<input id="female" name="sex" type="radio" class="forminput" />
<label for="male" class="forminput">Male</label>
<input id="male" name="sex" type="radio" class="forminput" />
<label for="state" class="formlabel">State</label>
<select id="state" name="state" class="forminput">
<option>ACT</option>
<option>New South Wales</option>
<option>Northern Territory</option>
<option>Queensland</option>
<option>South Australia</option>
<option>Tasmania</option>
<option>Victoria</option>
<option>Western Australia</option>
</select>
<label for="deadseal" class="formlabel">Death certificate</label>
<input id="deadseal" name="deadseal" type="file" class="forminput" />
</fieldset>
In the above example, the DOB does have an extra <div> cluttering things up. You could get rid of it if you style up the date slashes as part of the :after pseudo-element where needed.
Turns out okay in Opera 11.60, Firefox 11, Google Chrome 18 and Internet Explorer 8.
I would lookup using the div tag to layout data on a page.
Tables are still very much useful for tabular data, but its frowned upon for laying out a page.
View source here on stackoverflow.com, there's probably some good examples.
Think about putting field names above the field, rather than beside. I find this works about the best.
HTML
<form>
<div id="personal_name">
<label>Name</label>
<input name="name" />
</div>
</form>
CSS
form
{display: table}
#personal_name
{display: table-row}
#personal_name input, #personal_name label
{display: table-cell}
I think this is enough.