horizontally aligning labels with input text - html

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/

Related

Formatting input fields

Just have a quick question, I am working on a website and as you can see I have created a few input fields. Ideally I wanted all my input fields to be skewed to the far right, which they are. Unfortunately, they are overly bunched without much padding. I've tried to add a class to my input fields and add appropriate padding via the CSS, but I've only managed managed to get them to go all to the far right.
So my question is, what do I need to add so my input fields are to the far right AND spaced appropriately?
<form action="demo_form.asp">
First Name: <input type="text" name="fname" class="test" required>
<br>Last Name: <input type="text" name="lname" class="test" required>
<br>Contact Me By:
<select name="contactuser" form="carform" class="test"">
<option value="email">Email</option>
<option value="phone">Phone</option>
</select>
<br>Email: <input type="text" name="email" class="test" required>
<br>Phone: <input type="text" name="phone" class="test" required>
<br>Zip Code: <input type="text" name="zipcode" class="test" required>
<br>
<input type="submit">
CSS
.test {
position: absolute;
right: 0;
}
You need to apply a margin.
input{
margin: 5px;
}
CODEPEN DEMO
line-height seems to be the precise way if you don't want to mess with changing anything.
You can just call the form in the CSS and add the line-height there or give the form a class and do the same which will be better
form {
line-height: 30px;
}
This is what i tested with and it spaced things out:
Fiddle - https://jsfiddle.net/20LcL21k/1/
I would use
http://materializecss.com/forms.html
Or bootstrap, but material have such a nice way of doing forms

How do I make sure my text and textboxes are aligned horizontally?

What is a quick and easy way to make sure that my text and textboxes are lined up correctly on all screen sizes?
<style>
form {display:table;}
label {display:table-row}
label span , input {display:table-cell;}
</style>
<form>
<label>
<span>Name:</span>
<input type="text" name="Name"/>
</label>
<label>
<span>Phone:</span>
<input type="text" name="Phone"/>
</label>
</form>
Works for IE8 and newer

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.

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.