Adjusting the floating elements on a webpage - html

I'm trying to achieve the following result:
Email Password
[Email box] [Password Box] [Log In]
[]keep me logged in Forgot Password?
I've been successful in implementing the first two lines (Email ... [Log In]) but can't shape the last line.
Here's the code.
<ul>
<li>
<label for="mail">Email: </label><br>
<input type="email" name="mail" /><br>
<input type="checkbox" name="stayLoggedIn" />
<small>Keep me signed in</small>
</li>
<li>
<label for="paswrd">Password: </label><br>
<input type="password" name="paswrd" /><br>
<small>Forgot Password?</small>
</li>
<li><button type="button" name="login">Log In</button></li><br><p> </p>
</ul>
The CSS code is as follows.
header ul {float: right;}
header ul li {
display: inline-block;
color: #FFEBCD;
font-family: "Maiandra GD";
}
header small {float: right;}

You will need to do this with two div's one float to the left the second float to the right
see an example
<div class="left_div">
<label for="mail">Email: </label><br>
<input type="email" name="mail" /><br>
<input type="checkbox" name="stayLoggedIn" />
<small>Keep me signed in</small>
</div>
<div class="right_div">
<label for="paswrd">Password: </label><br>
<input type="password" name="paswrd" /><br>
<small>Forgot Password?</small>
</div>
The CSS code
.left_div {
float: left;
width: 300px;
}
.right_div {
float: right;
width: 300px;
}

Related

Struggling to align form elements

I've been trying to get my form elements to align for ages and tried restarting multiple times, but it's just not working with me. This is what I'm trying to get:
This is what I get:
JSFiddle demo
My main problem is probably the radio buttons, which I can't get text to the right of when they're floated right, and for some reason can't get to float left without floating everything left.
I am really new to HTML, so I might just be missing something obvious?
.container {
margin-left: 300px;
margin-right: 600px;
margin-bottom: 200px;
line-height: 3;
display: inline-block;
}
.container input {
width: 700px;
float: right;
}
.container select {
width: 400px;
float: right;
}
<div class="container">
<form action="user data.php">
<input type="text" name="fname" value="First Name"> <br>
<input type="text" name="lname" value="Last Name"> <br>
<input type="text" name="email" value="e-mail Address"> <br>
<input type="text" name="cell" value="Cell Number"> <br>
<input type="text" name="id" value="ID/Passport Number"> <br>
<input type="text" name="dob" value="Date of Birth"> <br>
<label for="course">Course:</label>
<select name="course"></select> <br>
<label for="hlevel">Highest Education Level:</label>
<select name="hlevel"></select> <br>
<p>Identification Type:</p>
<input type="radio" name="idtype" id="passnum" style="width: 5px;" value="Passport Number">
<label for="passnum"> Passport Number </label> <br>
<input type="radio" name="idtype" id="idnum" value="ID Number">
<label for="idnum"> ID Number </label> <br>
<label for="gender">Gender:</label>
<label for="pgroup">Population Group:</label>
<select name="pgroup"></select> <br>
<input type="submit" name="submitbtn" value="Submit Info">
</form>
</div>
In HTML, add class to submit button
<input class="submit-btn" type="submit" name="submitbtn" value="Submit Info">
In CSS, add below
form {
max-width: 700px;
}
input {
max-width: 700px;
}
.submit-btn {
max-width: 80px;
}

Layout form with CSS so that form is centered but with left aligned variable width fields and right aligned button

I am trying to format a form using CSS. Here is my sample HTML:
<div id='login'>
<h3>Log In</h3>
<form action='/' method='post' accept-charset='UTF-8'>
<div class='centerform'>
<label for='userId'>User Id:</label>
<input id='userId' maxlength='30' />
<label for='password'>Password:</label>
<input id='password' type='password' maxlength='30' />
<label for='longer'>Longer Field:</label>
<input id='longer' maxlength='50' width='50' />
<label for='checkbox'>I have a bike:</label>
<input id='checkbox' type='checkbox' name='vehicle' value='Bike'>
<input type='submit' class='button' value='Submit' />
</div>
</form>
</div>
I want the form to look like this:
Notice that the input fields are left aligned to each other, the labels are right aligned to each other, the submit button is right aligned to the entire form, and the whole thing needs to be centered horizontally in the page. This same CSS needs to work for many different forms with variable width fields.
My current CSS looks like this:
.centerform label{
float: left;
width: 50%;
text-align: right;
/*background-color: green;*/
}
.centerform input{
font-size: 100%;
float: right;
width: 50%;
}
The only thing that gets right is the alignment of the labels. I also am not sure on how to indicate the lengths of the fields. Any width I set in the html gets overridden by the CSS.
I DO NOT want to use any hard coded pixel or percent sizes except for the variable length fields if necessary.
EDIT: I figured out how to have variable length fields by using the size attribute.
This layout might be of help to you. I have given the dimensions in percentage as asked.
.centerform label {
text-align: right;
display: inline-block;
width: 16%;
}
.centerform input {
display: inline-block;
width: 82%;
}
.button {
width: 20% !important;
float: right;
}
<div id='login'>
<h3>Log In</h3>
<form action='/' method='post' accept-charset='UTF-8'>
<div class='centerform'>
<label for='userId'>User Id:</label>
<input id='userId' maxlength='30' />
<label for='password'>Password:</label>
<input id='password' type='password' maxlength='30' />
<label for='longer'>Longer Field:</label>
<input id='longer' maxlength='50' width='50' />
<label for='checkbox'>I have a bike:</label>
<input id='checkbox' type='checkbox' name='vehicle' value='Bike'>
<input type='submit' class='button' value='Submit' />
</div>
</form>
</div>
.centerform ul{margin:0;padding:0}
.centerform ul li{list-style:none;padding:5px 0;}
.centerform label{width:18%;display:inline-block;text-align:right;}
.centerform input{display:inline-block;width:80%;text-align:left;}
.centerform input[type='checkbox']{display:inline;width:auto;}
.centerform input[type='submit'] {display:inline;width:auto;float:right;}
<div id='login'>
<h3>Log In</h3>
<form action='/' method='post' accept-charset='UTF-8'>
<div class='centerform'>
<ul>
<li>
<label for='userId'>User Id:</label>
<input maxlength='30' />
</li>
<li>
<label for='password'>Password:</label>
<input type='password' maxlength='30' />
</li>
<li>
<label for='longer'>Longer Field:</label>
<input maxlength='50' width='50' />
</li>
<li>
<label for='checkbox'>I have a bike:</label>
<input type='checkbox' name='vehicle' value='Bike'>
</li>
<li>
<label></label>
<input type='submit' class='button' value='Submit' />
</li>
</ul>
</div>
</form>
</div>
Hope this is what you are expecting, you can simply adjust .centerform label and .centerform input WIDTH to adjust and fit the form's overall width.

html form checkbox not positioning as expect

hello i'm creating a login form .but my check box and term text related to it not positioning correctly .i have add <br> tag but no effect .i tried clearfix it's not work either.here is the fiddle preview.
this is my html code
<div class="mainlog">
<form>
<label class="la" for="xname">Name</label><input name="xname" class="in" value="" type="text"><br>
<label class="la" for="xemail">Email</label><input name="xemail" class="in" value="" type="text"><br>
<label class="la" for="xpass">password</label><input name="xpass" class="in" value="" type="text"><br>
<label class="la" for="xpasscon">confirm</label><input name="xpasscon" class="in" value="" type="text"><br>
<input type="checkbox" name="term"/><label class="lb" for="term" >I have read and agree to the Terms of Use and the Privacy Policy</label><br>
<input type="submit" value="Sign Up" />
</form>
</div>
Wrap the checkbox and text in a div and float it left. Avoid the usage of <center> it will not be supported in HTML5
.mainlog {
width: 450px;
height: 250px;
border: 5px solid #DBDBDB;
border-radius: 5px;
padding: 20px;
}
.in {
padding: 8px;
border: 1px solid #DFDFDF;
width: 250px;
float: left;
margin-bottom: 10px;
border-radius: 5px;
}
.la {
width: 120px;
float: left;
text-align: left;
text-transform: uppercase;
color: #6B6B6B;
clear: both;
}
.lb {} .checkbox {
float: left;
}
}
<center>
<div class="mainlog">
<form>
<label class="la" for="xname">Name</label>
<input name="xname" class="in" value="" type="text">
<br>
<label class="la" for="xemail">Email</label>
<input name="xemail" class="in" value="" type="text">
<br>
<label class="la" for="xpass">password</label>
<input name="xpass" class="in" value="" type="text">
<br>
<label class="la" for="xpasscon">confirm</label>
<input name="xpasscon" class="in" value="" type="text">
<br>
<div class="checkbox">
<input type="checkbox" name="term" />
<label class="lb" for="term">I have read and agree to the Terms of Use and the Privacy Policy</label>
<br />
</div>
<input type="submit" value="Sign Up" />
</form>
</div>
</center>
Quick fix: wrapp checkbox with it's label into div with class "width".
Then in CSS add ".width" with styles: width:100%; clear:both.
.width{
width:100%;
clear:both;
}
Demo
I did a minor change in your code and it looks good to me. I am not sure if this is what you were looking for.
Please check the fiddle here.
These were the changes I made.
HTML:
<div class="lb"> <!-- added class "lb" to <div> and removed it from <label> -->
<input type="checkbox" name="term" />
<label for="term">I have read and agree to the Terms of Use and the Privacy Policy</label>
</div>
CSS:
.lb {
float:left; /* Floats the element to left */
}
I hope this works for you. :)
P.S. I have removed all the <br> tags inside the <form>

Align input controls on page

I have a form with 4 textboxes, a checkbox and a select with their labels on their left. Here's my code:
<fieldset class="form-field">
<legend>
<label class="form-field k-checkbox">Parent Material</label>
</legend>
<ul class="form-field">
<li>
<label for="use_test_certificate" class="form-field">Use Test Certificate</label>
<input type="checkbox" name="use_test_certificate" class="k-checkbox form-field" />
</li>
<li>
<label for="parent_material" class="form-field">Material</label>
<select name="parent_material" class="form-field"></select>
</li>
<li>
<label for="proof_stress" class="form-field">0.2% Proof Stress</label>
<input type="text" name="proof_stress" size="24" maxlength="23" style="width:170px;" class="k-textbox form-field" />
</li>
<li>
<label for="do_weld_calculation" class="form-field">Do Weld Calculation</label>
<input type="checkbox" name="do_weld_calculation" class="k-checkbox form-field" />
</li>
<li>
<label for="weld_redistribution_factor" class="form-field">Weld Redistribution Factor</label>
<input type="text" name="weld_redistribution_factor" size="24" maxlength="23" style="width:170px;" class="k-textbox form-field" />
</li>
</ul>
</fieldset>
Problem is that the select displays next to the checkbox and not next to it's label. And when I increase the window size it jumps up to next to my first textbox. How can I tell it to show next to it's label. I'm not a CSS expert. I normally can work things out for myself, but this one baffles me completely. Any help is appreciated.
Amanda
Seeing as you haven't shown your CSS, I might as well show you the ideal solution using nothing but form elements :)
Note how I have changed the name attributes to id. The id, which needs to be unique, is used to identify the corresponding label by means of the labels for attribute.
Have a look at this fiddle!
CSS
fieldset {
width: 500px;
}
label {
display: block;
float: left;
clear: left;
width: 200px;
margin: 10px;
}
input, select {
display: block;
float: left;
margin: 10px;
}
input[type=text] {
width: 170px;
}
HTML
<fieldset class="form-field">
<legend>Parent Material</legend>
<label for="use_test_certificate" class="form-field">Use Test Certificate</label>
<input type="checkbox" id="use_test_certificate" class="k-checkbox form-field" />
<label for="parent_material" class="form-field">Material</label>
<select id="parent_material" class="form-field"></select>
<label for="proof_stress" class="form-field">0.2% Proof Stress</label>
<input type="text" id="proof_stress" maxlength="23" class="k-textbox form-field" />
<label for="do_weld_calculation" class="form-field">Do Weld Calculation</label>
<input type="checkbox" id="do_weld_calculation" class="k-checkbox form-field" />
<label for="weld_redistribution_factor" class="form-field">Weld Redistribution Factor</label>
<input type="text" id="weld_redistribution_factor" maxlength="23" class="k-textbox form-field" />
</fieldset>

Why won't my two column form line up correctly?

I'm learning some css and want to make a two column form, without any table tags and such.
This is what i have got (code from CSS Cookbook 3ed edition).
JSfiddle HERE...
HTML code:
<div class="container">
<form id="regform" name="regform" method="post" action="/regform.php">
<div id="register">
<h4>Register</h4>
<label for="fmlogin">Login</label>
<input type="text" name="fmlogin" id="fmlogin" />
<label for="fmemail">Email Address</label>
<input type="text" name="fmemail" id="fmemail" />
<label for="fmemail2">Confirm Address</label>
<input type="text" name="fmemail2" id="fmemail2" />
<label for="fmpswd">Password</label>
<input type="password" name="fmpswd" id="fmpswd" />
<label for="fmpswd2">Confirm Password</label>
<input type="password" name="fmpswd2" id="fmpswd2" />
</div>
<div id="contactinfo">
<h4>Contact Information</h4>
<label for="fmfname">First Name</label>
<input type="text" name="fmfname" id="fmfname" />
<label for="fmlname">Last Name</label>
<input type="text" name="fmlname" id="fmlname" />
<label for="fmaddy1">Address 1</label>
<input type="text" name="fmaddy1" id="fmaddy1" />
<label for="fmaddy2">Address 2</label>
<input type="text" name="fmaddy2" id="fmaddy2" />
<label for="fmcity">City</label>
<input type="text" name="fmcity" id="fmcity" />
<label for="fmstate">State or Province</label>
<input type="text" name="fmstate" id="fmstate" />
<label for="fmzip">Zip</label>
<input type="text" name="fmzip" id="fmzip" size="5" />
<label for="fmcountry">Country</label>
<input type="text" name="fmcountry" id="fmcountry" />
<input type="submit" name="submit" value="send" class="submit" />
</div>
</form>
</div>
CSS code:
label {
margin-top: .33em;
display: block;
}
input {
display: block;
width: 250px;
}
#register {
float: left;
}
#contactinfo {
padding-left: 275px;
}
Because you float one div and not the other.
With a few simple CSS changes it'll work (as long as the h4 does not span multiple lines):
#register {
float: left;
width: 275px;
}
#contactinfo {
float: left;
}
See the updated fiddle.
Here's how I'd debug (except I'd use Firebug or another Inspect/devtools): http://jsfiddle.net/PhilippeVay/yuxTA/2/
As stated by #Arjan in his answer, this is due to floating and its effects.
Uncomment the last CSS declaration for a solution that won't modify layout. Also add margin-top to both columns or padding-top if you want a vertical margin back...
Another option is to remove the margins from the h4 (although, as said in other answers, floating [or similar] both columns makes more sense).
h4 {margin: 0;}
You have to float all the div in your containter
#register {
float: left;
}
#contactinfo {
float:left;
margin-left:30px; /*increase or decrease if you like*/
}