I have added a !important to make sure that my css rules comes first but my inputs still behave like it was display in block; fiddle
input{
display: inline!important;
}
<p>My name is
<input type="text" placeholder="Name" class="form-control" style='display:inline;'/>
from USA. And I'm <input type="text" placeholder="21" class="form-control" style='display:inline;'/> years old.
</p>
All you need to do is reset the width to auto - it was 100%. It's worth noting that the Bootstrap styling is coming from the .form-control selector; use that to overwrite it.
Updated Example
.form-control {
width:auto;
display:inline-block;
}
No need for inline styling or !important.
<p>My name is
<input type="text" placeholder="Name" name="name" class="form-control" style='display:inline; width:100px'/>
from USA. And I'm <input type="text" name="age" placeholder="21" class="form-control" style='display:inline; width:100px'/> years old.
</p>
you can resize your input button with CSS including width in input style
I added the form tag for inline forms, it works when you have enough room on the page for one line.
<form class="form-inline" role="form">
<div class="form-group">
<p>My name is
<input type="text" placeholder="Name" name="name" class="form-control" style='display:inline;'/>
from USA. And I'm <input type="text" name="age" placeholder="21" class="form-control" style='display:inline;'/> years old.
</p>
</div>
</form>
Here's some more information explaining it from getbootstrap.com.
"Add .form-inline to your for left-aligned and inline-block controls. This only applies to forms within viewports that are at least 768px wide.
Requires custom widths
Inputs, selects, and textareas are 100% wide by default in Bootstrap. To use the inline form, you'll have to set a width on the form controls used within."
http://getbootstrap.com/css/
Works in jsfiddle when it's wide enough.
Related
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/
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.
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.
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.
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.