I simpley want the div with ID #knop next to the #plusmin when the screen is wide enough. When the screen gets smaller than the #knop has to get under the Plusmin...
I tried al kind of display options in the CSS with no effect...
See page: https://www.tricotstoffen.nl/tricot-stoffen/dierenprint/stenzo-tricot-konijnen-zwart-wit-bio-katoen.html
<div class="product-add-form">
<form action="https://www.tricotstoffen.nl/checkout/cart/add/uenc/aHR0cHM6Ly93d3cudHJpY290c3RvZmZlbi5ubC90cmljb3Qtc3RvZmZlbi9kaWVyZW5wcmludC9zdGVuem8tdHJpY290LWtvbmlqbmVuLXp3YXJ0LXdpdC1iaW8ta2F0b2VuLmh0bWw,/product/324/" method="post"
id="product_addtocart_form">
<input type="hidden" name="product" value="324" />
<input type="hidden" name="selected_configurable_option" value="" />
<input type="hidden" name="related_product" id="related-products-field" value="" />
<input name="form_key" type="hidden" value="xmAH6XJ8Kvrn2FTs" /> <style type="text/css">
#box{
width: 100%;
min-height: 55px;
display: inline-table;
}
#plusmin{
width: 210px;
height: 55px;
float: left;
padding-left: 3px;
margin-bottom:10px;
}
#knop{
height: 55px;
width: 175px;
float: left;
}
</style>
<div class="box-tocart" id="box">
<div class="fieldset">
<div class="field qty" id="plusmin">
<label class="label" for="qty"><span>Aantal</span></label>
<div class="control" data-bind="scope: 'qty_change'">
<button data-bind="click: decreaseQty">-</button>
<input data-bind="value: qty()"
type="number"
name="qty"
id="qty"
maxlength="12"
title="Aantal" class="input-text qty"
data-validate="{"required-number":true,"validate-item-quantity":{"minAllowed":0.5}}"
/>
<button data-bind="click: increaseQty">+</button>
</div>
<script type="text/x-magento-init">
{
"*": {
"Magento_Ui/js/core/app": {
"components": {
"qty_change": {
"component": "Jilco_plusminknoppen/js/view/product/view/qty_change",
"defaultQty": 0.5 }
}
}
}
}
</script>
</div>
<div class="actions" id="knop">
<button type="submit"
title="In Winkelwagen"
class="action primary tocart"
id="product-addtocart-button">
<span>In winkelwagen</span>
</button>
</div>
</div>
</div>
<script type="text/x-magento-init">
{
"#product_addtocart_form": {
"Magento_Catalog/product/view/validation": {
"radioCheckboxClosest": ".nested"
}
}
}
</script>
</form>
</div>
div#plusmin on the example page you provided has an inline style attribute, which was probably set by some magento javascript. You can see it in your browsers development console:
<div class="field qty" id="plusmin" style="width: 100%; display: block;">
...
</div>
This is screwing you over because inline style attribute rules take precedence over css style rules. As a quick fix you could append the css rule that sets the div's width with !important. Such rules cannot be overridden by style attribute rules.
#plusmin{
width: 210px !important;
...
}
Have a look here, you need to use #media queries to adjust your css when the screen is x pixels wide.
As as example:
#media screen and (max-width: 400px) {
#knop {
width: 100%;
}
#plusmin {
width: 100%;
}
}
Related
I am trying to make an image on the side remain the same height as the calculator.
Where should either the css or html go within the structure? I would like to keep the aspect ratio as close to possible
Code: http://jsbin.com/gijitaluta/edit?html,output
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Calculator</title>
<link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet"></head>
<body>
<div id="calculatorcontainer">
<div id="maincontainer">
<aside class="imageContainer">
<img src="">
</aside>
<form action="" method="post" id="theForm">
<fieldset >
<legend>Calculator</legend>
<h4>Use this form to calculate the order total</h4>
<div class="form-group">
<label for="quantity">Quantity</label>
<input class="form-control" id="quantity" type="number" value="1"/>
</div>
<div class="form-group">
<label for="ppu">Price Per Unit</label>
<input type="text" class="form-control" id="ppu" placeholder="1.00" required>
</div>
<div class="form-group">
<label for="tax">Tax Rate (%)</label>
<input type="text" class="form-control" id="tax" placeholder="0.0" required>
</div>
<div class="form-group">
<label for="discount">Discount (%)</label>
<input type="text" class="form-control" id="discount" placeholder="0.00" required>
</div>
<div class="form-group">
<label for="ttl">Total</label>
<input type="text" class="form-control" id="output" placeholder="0.00">
</div>
<div>
<button type="submit" class="btn btn-calculate" id="submit">Calculate</button>
</div>
</fieldset>
</form>
</div>
<footer class="footer">
<h3>Copyright CSUN</h3>
</footer>
</div>
</body>
</html>
This way uses a table. Doesn't require many changes. You'll need a version of the image with the gray edges removed and you'll have to play with padding and/or margins.
http://jsbin.com/xepiren/edit?html,css,output
td {
background-color:#fff;
}
form {
padding: 5%;
/*width: 50%;*/
font-family: 'Open Sans'
}
#theForm {
background-color: white;
}
legend {
color: red;
font-size: 1.3em;
}
#maincontainer {
margin: 5%;
}
fieldset {
}
img {
/*width:30%;*/
float: right;
height: 430px
}
body {
background-color: grey;
}
fieldset {
padding: 10%;
}
#calculatorcontainer {
margin: 10%;
border-style: solid;
border-style: groove;
}
h4 {
margin: 0px;
}
footer {
padding: 10px;
border-style: solid;
border-style: groove;
}
footer h3 {
color:red;
font-size:80%
}
input {
width: 90%
}
#submit {
margin:10px
}
#media (max-width: 479px) {
img {
width:30%;
float: right;
height: 230px
}
fieldset {
padding: 0%;
}
form {
font-size: 7px;
}
footer {
padding: 7px;
}
footer h3 {
color:red;
font-size:10%
}
}
#media (min-width: 1000px) {
img {
width:30%;
float: right;
height: 480px
}
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Calculator</title>
<link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet"></head>
<body>
<div id="calculatorcontainer">
<div id="maincontainer">
<table>
<tr>
<td>
<form action="" method="post" id="theForm">
<fieldset >
<legend>Calculator</legend>
<h4>Use this form to calculate the order total</h4>
<div class="form-group">
<label for="quantity">Quantity</label>
<input class="form-control" id="quantity" type="number" value="1"/>
</div>
<div class="form-group">
<label for="ppu">Price Per Unit</label>
<input type="text" class="form-control" id="ppu" placeholder="1.00" required>
</div>
<div class="form-group">
<label for="tax">Tax Rate (%)</label>
<input type="text" class="form-control" id="tax" placeholder="0.0" required>
</div>
<div class="form-group">
<label for="discount">Discount (%)</label>
<input type="text" class="form-control" id="discount" placeholder="0.00" required>
</div>
<div class="form-group">
<label for="ttl">Total</label>
<input type="text" class="form-control" id="output" placeholder="0.00">
</div>
<div>
<button type="submit" class="btn btn-calculate" id="submit">Calculate</button>
</div>
</fieldset>
</form>
</td>
<td>
<aside class="imageContainer">
<img src="https://image.ibb.co/iUhiUv/Screen_Shot_2017_08_03_at_12_12_16_PM.png">
</aside>
</td>
</tr>
</table>
</div><!-- End "maincontainer" -->
<footer class="footer">
<h3>Copyright CSUN</h3>
</footer>
</div>
</body>
</html>
I am trying to create a simple page navigation consisting of three parts:
A few previous page numbers (if any)
The current page number (this must be centered)
A few upcoming page numbers (if any)
The important thing is that the current page number is always horizontally centered within the parent container. The other two parts should take up the remaining horizontal space evenly.
This JSFiddle illustrates my two attempts at solving this problem.
Solution 1: use text-align: center. This achieves the desired result but only if both sides are equal in width. If not the current page number will not be in the center.
HTML
<div class="container">
<input type="button" value="47">
<input type="button" value="48">
<input type="button" value="49">
<input type="text" size="5" maxlength="5" value="50">
<input type="button" value="51">
<input type="button" value="52">
<input type="button" value="53">
</div>
CSS
.container, input {
text-align: center;
}
Solution 2: use manually specified widths to distribute the horizontal space evenly. This effectively centers the current page number under all circumstances but it requires you to hardcode widths.
HTML
<div class="container">
<div class="left">
<input type="button" value="47">
<input type="button" value="48">
<input type="button" value="49">
</div>
<div class="right">
<input type="button" value="51">
<input type="button" value="52">
<input type="button" value="53">
</div>
<div class="center">
<input type="text" size="5" maxlength="5" value="50">
</div>
</div>
CSS
.left {
width: 40%;
float: left;
text-align: right;
}
.right {
width: 40%;
float: right;
text-align: left;
}
.center {
width: 20%;
margin-left: 40%;
}
Neither of these solutions really do what I want. Is there any way to have the current page number centered while allowing the other elements to align to its natural size, rather than to an arbitrary pixel or percentage width?
Try this CSS table layout follows.
.container {
width: 100%;
display: table;
border-collapse: collapse;
table-layout: fixed;
}
.left, .center, .right {
display: table-cell;
border: 1px solid red;
text-align: center;
}
.center {
width: 50px;
}
<div class="container">
<div class="left">
<input type="button" value="47">
<input type="button" value="48">
<input type="button" value="49">
</div>
<div class="center">
<input type="text" size="5" maxlength="5" value="50">
</div>
<div class="right">
<input type="button" value="51">
<input type="button" value="52">
<input type="button" value="53">
</div>
</div>
jsfiddle
You should use flex and float properties together, checkout my solution:
.container {
display: -webkit-flex; /* Safari */
display: flex;
}
.container, input {
text-align: center;
}
.container:after {
content:"";
position: absolute;
z-index: -1;
top: 0;
bottom: 0;
left: 50%;
border-left: 2px dotted #ff0000;
}
.left {
display: inline-block;
flex: 1;
}
.left input {
float: right;
}
.right {
display: inline-block;
flex: 1;
}
.right input {
float: left;
}
.center {
display: inline-block;
}
<div class="container">
<div class="left">
<input type="button" value="48">
<input type="button" value="49">
</div>
<div class="center">
<input type="text" size="5" maxlength="5" value="50">
</div>
<div class="right">
<input type="button" value="51">
<input type="button" value="52">
<input type="button" value="53">
</div>
</div>
You can use the CSS property display with the value flex in the wrapper, and the property flex in the children.
To learn more about it, check the following resource: A Complete Guide to Flexbox
Here is an example:
.wrapper {
display: flex;
}
.wrapper > div {
text-align: center;
flex: 1;
border: 1px solid #000;
}
<div class="wrapper">
<div>
<button>1</button>
<button>2</button>
</div>
<div>
<button>3</button>
</div>
<div>
<button>4</button>
<button>5</button>
<button>6</button>
</div>
</div>
Here is a solution you might consider:
Use hidden buttons to always maintain the same number of tags on left and right side
<div class="container">
<input style="visibility: hidden" type="button" value="0">
<input style="visibility: hidden" type="button" value="0">
<input style="visibility: hidden" type="button" value="0">
<input type="text" size="5" maxlength="5" value="1">
<input type="button" value="2">
<input type="button" value="3">
<input type="button" value="4">
</div>
Instead of specifying the width in % you can use CSS calc to split the full width in 3 parts:
[50% - 25px][50 px][50% - 25px]
Then right-align the left part, left align the right part and you're done. When using SASS or LESS you only need to specify the width of the center part.
.container {
width: 100%;
white-space: nowrap;
overflow: hidden;
}
.container > * {
display: inline-block;
}
.container .left {
width: calc(50% - 25px);
text-align: right;
}
.container > input {
width: 50px;
margin: 0px;
text-align: center;
}
.container .right {
width: calc(50% - 25px);
text-align: left;
}
<div class="container">
<div class="left">
<input type="button" value="48" />
<input type="button" value="49" />
</div>
<input type="text" maxlength="5" value="50" />
<div class="right">
<input type="button" value="51" />
<input type="button" value="52" />
<input type="button" value="53" />
</div>
</div>
I'm having trouble making a form using tables. I'm trying to make the <textarea> comment box row take up the full width. The problem is unknown to me, as I don't know why it won't work.
.full_width {
width: 100%
}
.table {
display: table; width: 100%;
}
.table_row {
display: table-row; width: 100%;
}
.table_cell {
display: table-cell
}
.label {
display: block
}
.two_cell
{
width: 48%;
}
#company_cell
{
padding-left: 4%;
}
.table_cell {
padding-bottom: 18px
}
<form class="table" method="post">
<div class="table_row">
<div class="table_row full_width">
<div class="table_cell">
<span>Name</span>
<input name="name" class="full_width" type="text" value=""/>
</div>
<div class="table_cell">
<span>Company</span>
<input name="company" class="full_width" type="text" value=""/>
</div>
</div>
</div>
<div class="table_row">
<div class="table_row full_width">
<div class="table_row">
<span>Comment</span>
</div>
<div class="table_row full_width">
<textarea name="comment" class="full_width" value="SEND"></textarea>
</div>
</div>
</div>
</form>
Here is the fiddle I'm playing around with https://jsfiddle.net/bpo7tujp/
The nature of your nested markup isn't wholly valid- in addition the logic conflicts somewhat.
Solution 1: table-caption
What you are effectively after is a CSS version of colspan, you can achieve this by changing your HTML to that below, and implementing table-caption
.full_width {
width: 100%
}
.table {
display: table;
width: 100%;
}
.table_row {
display: table-row;
width: 100%;
}
.table_cell {
display: table-cell
}
.label {
display: block
}
.two_cell {
width: 48%;
}
#company_cell {
padding-left: 4%;
}
.table_cell {
padding-bottom: 18px
}
.table_caption {
display: table-caption;
caption-side: bottom;
}
<form class="table" method="post">
<div class="table_row">
<div class="table_cell">
<span>Name</span>
<input name="name" class="full_width" type="text" value="" />
</div>
<div class="table_cell">
<span>Company</span>
<input name="company" class="full_width" type="text" value="" />
</div>
</div>
<div class="table_caption">
<span>Comment</span>
<br />
<textarea name="comment" class="full_width" value="SEND"></textarea>
</div>
</form>
Solution 2 (advised): No tables
With that said, you would be far better not using tables for layouting, as evidenced by how simple it is to create the same:
.column {
float: left;
width: 50%;
}
input,
textarea {
width: 100%;
}
<div class="columns">
<div class="column">
<span>Name</span>
<input name="name" class="full_width" type="text" value="" />
</div>
<div class="column">
<span>Company</span>
<input name="company" class="full_width" type="text" value="" />
</div>
</div>
<span>Comment</span>
<textarea name="comment" class="full_width" value="SEND"></textarea>
How can i center the form called form_login horizontally and vertically in my page ?
Here is the HTML I'm using right now:
<body>
<form id="form_login">
<p>
<input type="text" id="username" placeholder="username" />
</p>
<p>
<input type="password" id="password" placeholder="password" />
</p>
<p>
<input type="text" id="server" placeholder="server" />
</p>
<p>
<button id="submitbutton" type="button">Se connecter</button>
</p>
</form>
</body>
I have tried to do the following css but my form is never centered :
#form_login {
left: 50%;
top: 50%;
margin-left: -25%;
position: absolute;
margin-top: -25%;
}
you can use display:flex to do this : http://codepen.io/anon/pen/yCKuz
html,body {
height:100%;
width:100%;
margin:0;
}
body {
display:flex;
}
form {
margin:auto;/* nice thing of auto margin if display:flex; it center both horizontal and vertical :) */
}
or display:table http://codepen.io/anon/pen/LACnF/
body, html {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
display:table;
}
body {
display:table-cell;
vertical-align:middle;
}
form {
display:table;/* shrinks to fit content */
margin:auto;
}
If you want to do a horizontal centering, just put the form inside a DIV tag and apply align="center" attribute to it. So even if the form width is changed, your centering will remain the same.
<div align="center"><form id="form_login"><!--form content here--></form></div>
UPDATE
#G-Cyr is right. align="center" attribute is now obsolete. You can use text-align attribute for this as following.
<div style="text-align:center"><form id="form_login"><!--form content here--></form></div>
This will center all the content inside the parent DIV. An optional way is to use margin: auto CSS attribute with predefined widths and heights. Please follow the following thread for more information.
How to horizontally center a in another ?
Vertical centering is little difficult than that. To do that, you can do the following stuff.
html
<body>
<div id="parent">
<form id="form_login">
<!--form content here-->
</form>
</div>
</body>
Css
#parent {
display: table;
width: 100%;
}
#form_login {
display: table-cell;
text-align: center;
vertical-align: middle;
}
if you use a negative translateX/Y width and height are not necessary and the style is really short
#form_login {
left : 50%;
top : 50%;
position : absolute;
transform : translate(-50%, -50%);
}
<form id="form_login">
<p>
<input type="text" id="username" placeholder="username" />
</p>
<p>
<input type="password" id="password" placeholder="password" />
</p>
<p>
<input type="text" id="server" placeholder="server" />
</p>
<p>
<button id="submitbutton" type="button">Se connecter</button>
</p>
</form>
Alternatively you could use display: grid (check the full page view)
body {
margin : 0;
padding : 0;
display : grid;
place-content : center;
min-height : 100vh;
}
<form id="form_login">
<p>
<input type="text" id="username" placeholder="username" />
</p>
<p>
<input type="password" id="password" placeholder="password" />
</p>
<p>
<input type="text" id="server" placeholder="server" />
</p>
<p>
<button id="submitbutton" type="button">Se connecter</button>
</p>
</form>
The accepted answer didn't work with my form, even when I stripped it down to the bare minimum and copied & pasted the code. If anyone else is having this problem, please give my solution a try. Basically, you set Top and Left to 50% as the OP did, but offset the form's container with negative margins on the top and left equal to 50% of the div's height and width, respectively. This moves the center point of the Top and Left coordinates to the center of the form. I will stress that the height and width of the form must be specified (not relative). In this example, a 300x300px form div with margins of -150px on the top and left is perfectly centered no matter the window size:
HTML
<body>
<div class="login_div">
<form class="login_form" action="#">
</form>
</div>
</body>
CSS
.login_div {
position: absolute;
width: 300px;
height: 300px;
/* Center form on page horizontally & vertically */
top: 50%;
left: 50%;
margin-top: -150px;
margin-left: -150px;
}
.login_form {
width: 300px;
height: 300px;
background: gray;
border-radius: 10px;
margin: 0;
padding: 0;
}
JSFiddle
Now, for those wondering why I used a container for the form, it's because I like to have the option of placing other elements in the form's vicinity and having them centered as well. The form container is completely unnecessary in this example, but would definitely be useful in other cases. Hope this helps!
How about using a grid? it's 2019 and support is reasonable
body {
margin: 0;
padding: 0;
background-color: red;
}
.content {
display: grid;
background-color: bisque;
height: 100vh;
place-items: center;
}
<!DOCTYPE html>
<html>
<body>
<div class="content">
<form action="#" method="POST">
<fieldset>
<legend>Information:</legend>
<label for="name">Name:</label>
<input type="text" id="name" name="user_name">
</fieldset>
<button type="button" formmethod="POST" formaction="#">Submit</button>
</form>
</div>
</body>
</html>
I suggest you using bootstrap which works perfectly:
#import url('http://getbootstrap.com/dist/css/bootstrap.css');
html, body, .container-table {
height: 100%;
}
.container-table {
display: table;
}
.vertical-center-row {
display: table-cell;
vertical-align: middle;
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Login Page | ... </title>
<script src="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.1.0/bootstrap.min.js"></script>
</head>
<body>
<div class="container container-table">
<div class="row vertical-center-row">
<div class="text-center col-md-4 col-md-offset-4" style="">
<form id="login" action="dashboard.html" method="post">
<div class="username">
<div class="usernameinner">
<input type="text" name="username" id="username" placeholder="Login" />
</div>
</div>
<div class="password">
<div class="passwordinner">
<input type="password" name="password" id="password" placeholder="Mot de passe" />
</div>
</div>
<button id="login-button">Connexion</button>
<div class="keep"><input type="checkbox" /> Gardez moi connecté</div>
</form>
</div>
</div>
</div>
</body>
</html>
#form_login {
height:500px;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
<form id="form_login">
<p>
<input type="text" id="username" placeholder="username"/>
</p>
<p>
<input type="password" id="password" placeholder="password" />
</p>
<p>
<input type="text" id="server" placeholder="server" />
</p>
<p>
<button id="submitbutton" type="button">Se connecter</button>
</p>
</form>
What is the best way to align the following?
I want the .inputTitle on the left and the inputInput on the right with the error inbetween them both.
CSS:
.crud_form{
width:430px;
margin:10px solid;
font-family:Verdana, Geneva, sans-serif;
background:orange;
}
.inputTitle{
float:left;
clear:left;
margin:11px 10px 10px 0;
width:95px;
background:green;
}
.inputRequired{
float:left;
margin:5px;
width:113px;
background:blue;
}
.inputError{
float:left;
margin:10px;
background:red;
}
.crud_form select textarea{
float:left;
clear:both;
}
HTML:
<form action="#" method="post" accept-charset="utf-8" class="crud_form" enctype="multipart/form-data">
<span class="inputTitle">First Name</span><span class="inputInput"><input type="text" name="first_name" value="" id="first_name" /></span><span class="inputError"></span>
<span class="inputTitle">Last Name</span><span class="inputInput"><input type="text" name="last_name" value="" id="last_name" /></span><span class="inputError"></span>
<span class="inputTitle">Address</span><span class="inputInput"><textarea name="address" cols="40" rows="10" id="address" ></textarea></span><span class="inputError"></span>
<span class="inputTitle">Phone</span><span class="inputInput"><input type="text" name="phone" value="" id="phone" /></span><span class="inputError"></span>
<span class="inputTitle">Item</span><span class="inputInput"><select name="item" id="item">
<option value="Caps cost $15"></option>
<option value="Mugs cost $20"></option>
<option value="Childrens T-shirts, sizes 0 to 6">$10</option>
<option value="Ladies (no photo) cost $20"></option>
<option value="Men cost $20"></option>
</select></span>
<span class="inputError"></span>
<span class="inputTitle">Comments</span><span class="inputInput"><textarea name="comments" cols="40" rows="10" id="comments" ></textarea></span><span class="inputError"></span>
<input type="submit" value="Save" />
</form>
I don't know why everyone is using div's, span's and li's etc. It's simple, look at the example below:
label {
width: 150px;
padding-right: 20px;
display: inline-block;
}
<p>
<label for="IDofInput">text goes here</label>
<input type="text" id="IDofInput">
</p>
<p>
<label for="IDofInput">text goes here</label>
<input type="text" id="IDofInput">
</p>
<p>
<label for="IDofInput">text goes here</label>
<input type="text" id="IDofInput">
</p>
I want the .inputTitle on the left and the inputInput on the right
with the error inbetween them both.
The way that I have always done this was to set a width for them.
For example:
If you were to have 3 floated elements, and you wanted them to align perfectly within the "Container" per se, the Container would of course need a width set.
After you were to set the width of the Container, set the width of those 3 floated elements to equal the width of the Container.
See below:
HTML:
<div class="container">
<div class="inputTitle"></div>
<div class="inputError"></div>
<div class="inputInput"></div>
<div class="clear"></div>
</div>
CSS
.container {
width: 600px;
}
.inputTitle {
width: 200px;
float: left;
}
.inputError {
width: 200px;
float: left;
}
.inputInput {
width: 200px;
float: left;
}
.clear {
clear: both;
}
Ultimately you could add the clear: both; CSS Declaration on the Container, but I like to make a clear: both; Class just to be on the safe side.
Of course you can always use Labels, but setting a pre-defined width for a label via CSS would apply to all Labels, within a class and or id.
I hope that helps!
Thanks!
Aaron
To clean up the vertical alignment, you could wrap each label - input pair in a containing div, then float the inputs to the right. I am not sure based on your question if this is the alignment you are looking for, but it does have a nicer appearance.
HTML:
<form action="#" method="post" accept-charset="utf-8" class="crud_form" enctype="multipart/form-data">
<div class="formdiv">
<span class="inputTitle">First Name</span>
<span class="inputInput">
<input type="text" name="first_name" value="" id="first_name" />
</span>
<span class="inputError"></span>
</div>
<div class="formdiv">
<span class="inputTitle">Last Name</span>
<span class="inputInput">
<input type="text" name="last_name" value="" id="last_name" /></span>
<span class="inputError"></span>
</div>
<div class="formdiv">
<span class="inputTitle">Address</span>
<span class="inputInput"><textarea name="address" cols="40" rows="10" id="address" ></textarea></span><span class="inputError"></span>
</div>
<div class="formdiv">
<span class="inputTitle">Phone</span><span class="inputInput"><input type="text" name="phone" value="" id="phone" /></span><span class="inputError"></span>
</div>
<div class="formdiv">
<span class="inputTitle">Item</span><span class="inputInput"><select name="item" id="item">
<option value="Caps cost $15"></option>
<option value="Mugs cost $20"></option>
<option value="Childrens T-shirts, sizes 0 to 6">$10</option>
<option value="Ladies (no photo) cost $20"></option>
<option value="Men cost $20"></option>
</select></span>
<span class="inputError"></span>
</div>
<div class="formdiv">
<span class="inputTitle">Comments</span><span class="inputInput"><textarea name="comments" cols="40" rows="10" id="comments" ></textarea></span><span class="inputError"></span>
</div>
<input type="submit" value="Save" />
</form>
CSS:
.formdiv {
float: left;
width: 100%;
margin-bottom: 1em;
}
.crud_form{
width:430px;
margin:10px solid;
padding: 10px;
font-family:Verdana, Geneva, sans-serif;
background:orange;
}
.inputTitle {
float:left;
clear:left;
/* margin:11px 10px 10px 0; */
width:95px;
background:green;
}
.inputInput {
float: right;
}
.inputRequired{
float:left;
margin:5px;
width:113px;
background:blue;
}
.inputError{
float:left;
margin:10px;
background:red;
}
.crud_form select textarea{
float:left;
clear:both;
}
The best way to structure a two-column form is to use a two-column table element inside a form element. But as you say that you want “the error” (apparently, error indicator or error message) between input label (title) and input field, you actually want a three-column form, i.e. three-column table.
<form ...>
<table>
<tbody>
<tr><td class="inputTitle"><label for="first_name">First Name</label></td>
<td class="inputError"><span></span></td>
<td class="inputInput"><input type="text" name="first_name" id="first_name" /></td></tr>
</tbody>
</table>
</form>
This (apart from simulating it using CSS table features, which have limited browser support) is the only way to make browsers allocated widths to the columns, according to the width requirements of the content, instead of your making wild guesses on what might be needed.
Abstract
IMHO (and the W3C is backing me up), list semantics are best to describe form layouts - forms as lists of prompt data. In this presentation a grid is being used to layout the form controls.
Reference
to see a full depiction on how it's done, please refer to W3C's reference on this, originally published at the Opera developers community, on their Web Standards Curriculum.
Code Example / Implementation
HTML:
<form>
<ul>
<li><label for="realname">Name:</label><input type="text" name="name" value="" class="medium" id="realname" /></li>
<li><label for="address">Email:</label><input type="text" name="email" value="" class="medium" id="address" /></li>
<li><label for="messageBody">Comments:</label><textarea name="comments" cols="32" rows="8" class="long" id="messageBody"></textarea></li>
</ul>
</form>
CSS:
/* base font size, other measures relay on seventh parts of this */
body {
font-size: 14px;
line-height: 1.714em;
}
/* form styles */
form {
margin: 0;
width: 35.929em;
}
/* reset list styles to be used as form layout mechanism */
ul {
margin: 0;
padding: 0;
list-style-type: none;
}
li {
clear: both;
height: 1.714em;
margin: 0;
}
/* form controls styles */
fieldset {
height: 1.429em;
margin: 0 0 -.143em 0;
border: 0;
}
label {
display: block;
float: left;
clear: left;
width: 10.286em;
overflow: auto;
padding-right: 1.714em;
text-align: right;
}
input {
height: 1.143em;
border: .071em solid rgb(96,96,96);
padding: .071em;
line-height: .929em;
}
textarea {
height: 4.714em;
margin-bottom: .286em;
border: .071em solid rgb(96,96,96);
padding: 0;
}
input,
textarea {
margin-top: 0;
font-size: 100%;
display: block;
float: left;
overflow: hidden;
font-family: Futura,'Century Gothic',sans-serif;
font-size: 1em;
}
/* input and textarea variants */
.medium {
width: 11.714em;
}
.long {
width: 20.429em;
}
you can play with the full code example in this jsFiddle (this does not contain the IE stylesheet).
Update
I've edited the answer to include only the relevant code for a two column layout form. please refer to the above links for a fully working example.