HTML form textarea problem - html

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.

Related

horizontally aligning labels with input text

I have a form that should look like this one: http://jsfiddle.net/g6kQK/
but if I inspect the generated code this is what I get: http://jsfiddle.net/bxA5X/
The problem seems to be with
display: block;
float: left;
but if delete those attributes nothing changes in my form.
What is the default property for input type=text in html?
What should I set it to make it aligned with the text?
Thanks.
Remove the width from the .cardno div, and move the input element to the outside.
<label>card no</label>
<div class="cardno">04</div>
<input type="text" name="codcard" maxlength="11"/>
Updated Fiddle: http://jsfiddle.net/bxA5X/8/
Just remove diplay:block property form.usersetting input[name="codcard"]
here is what i got you the answer hope this is what you want... just see this fiddle
<form id="change_customer_data" class="usersetting" action="/">
<label>telephone</label>
<input type="text" name="tel" /><br>
<label>email</label>  
<input type="text" name="email"><br>
<label>card no:</label>
04<input type="text" name="codcard" maxlength="11"/>
http://jsfiddle.net/bxA5X/8/

Aligning textboxes via 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.

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 forms - alignment problem

How do I make forms with background colour? Using tables?
Also I can't seem to line up the text to the first row of each textarea?
Edit:
To clarify, this is my code:
Summary: <textarea rows="1" cols="50"> </textarea><br/><br/>
Changing the background colour of the form is very simple. Using CSS and a unique id, apply a style to the form:
<form id="myForm"></form>
Using CSS
#myForm {
background-color: your-color-of choice;
}
In fact, you don't even have to use an ID, but it's advisable if you are going to have several forms with each requiring a unique style. Otherwise, you could just reference the form element in your CSS as such: form { background-color: your-color-of choice; }
As far as aligning the text along with a text area, you can use plain CSS, divs, or tables. But I think you should ask this separately as it is another scope altogether. Do some research and search for other questions on alignment here on SO to see which method will work best for you.
To give you an idea, though, try this:
<form id="myForm">
<label for="myTextArea">Summary</label>
<textarea id="myTextArea"></textarea>
</form>
In CSS
#myForm {
width:500px
}
#myForm label {
float:left;
display:block;
width:150px;
}
#myForm textarea {
float:left;
width:200px;
}
I don't recommend you do it exactly this way, but this should give you a start.
If you will have many different fields in the form, you might consider wrapping each section in a fieldset:
<form id="myform">
<fieldset id="customerinfo">
<legend>Personal Info</legend>
Name: <input type="text" /><br/>
Address: <input type="text" /><br/>
etc...
</fieldset>
<fieldset id="orderinfo">
<legend>Your Order:</legend>
Product: <input type="text" /><br/>
Quantity: <input type="text" /><br />
etc...
</fieldset>
</form>
The fieldset lets you define a "legend" for the group of fields (the name at the top) and puts a box around them. IMHO it gives a pretty cool effect. And, of course, you can style them with css.
Good luck!

Django not rendering CSS correctly

I have a site that I'm creating, part in static HTML, the other part is served via Django. Since I want the look and feel to remain the same (who doesn't?) I have used CSS for the static site. That same CSS I have included (almost successfully) in the dynamic site.
When I create a form, I can get a very nice two column listing on the static side
Label Input
Label Input
Label Input
But, when I do the same code on the dynamic side, it's not so nice
Label Input
Label Input
Label Input
The CSS I'm using is:
form.login label.fixedwidth {
display: block;
width: 240px;
float: left;
}
\.
Sorry, here's my form:
<form action="" method="post" class="login">
<fieldset>
<div>
<label for="username" class="fixedwidth">User name:</label>
<input type="text" name="username" value="" id="username">
</div>
<div>
<label for="password" class="fixedwidth">Password:</label>
<input type="password" name="password" value="" id="password">
</div>
<input type="submit" value="login" />
</fieldset>
</form>
[edit]
So, I noticed that my two 'input type' lines didn't close the tag (no '/'). But, no difference.
[/edit]
Try
clear:both; overflow: auto
on the surrounding DIV.
By the way, a <ul> with <li> s may be semantically more fitting than <div>s here. Won't make a difference in the output though.