Im using flex to format input on a row format. But right now im trying to put label on top of those inputs and its not working. Im tried using display block and floating left or right but still remains on the left side. How should i style label so it floats to the top of those inputs?
This is the snippet:
.box {
padding-top: 1rem;
}
.inside-box {
max-width: 51rem;
margin: 0 auto;
}
.form-group {
display: flex;
flex-direction: column;
}
.row {
display: flex;
}
.razao-social-content {
flex: 2 1 auto;
/* grow shrink basis */
}
.rua-content {
flex: 6 1 auto;
}
.municipio-content {
flex: 4 1 auto;
}
.numero-content {
flex: auto 1 auto;
}
.bairro-content {
flex: 4 1 auto;
}
.telefone-content {
flex: 1 1 auto;
}
.email-content {
flex: 1 1 auto;
}
.categoria-content {
flex: 2 1 auto;
}
.controlador-content {
flex: 2 1 auto;
}
label {}
<div class="box">
<div class="inside-box">
<form action="" class="form-group">
<div class="row">
<label class="lb" for="name">Razão Social</label>
<input class="razao-social-content" type="text" id="name" placeholder="Informe o seu nome" required>
<label class="lb" for="cnpj_distribuidor">CNPJ</label>
<input class="cnpj-content" type="text" id="cnpj_distribuidor" placeholder="CNPJ" required>
</div>
<div class="row">
<label for="rua">Rua</label>
<input class="rua-content" type="text" id="rua" placeholder="Nome da rua" required>
<label for="municipio">Município</label>
<input class="municipio-content" type="text" id="municipio" placeholder="Nome do Município" required>
<label for="numero">Número</label>
<input class="numero-content" type="text" id="numero" placeholder="Número da Residência" required>
</div>
<div class="row">
<label for="bairro">Bairro</label>
<input class="bairro-content" type="text" id="bairro" placeholder="Nome do Bairro" required>
<label for="uf">Estado</label>
<input class="uf" type="text" id="uf" placeholder="Estado" required>
<label for="cep">CEP</label>
<input class="cep-content" type="text" id="cep" placeholder="CEP" required>
</div>
<div class="row">
<label for="telefone1">Telefone</label>
<input class="telefone-content" type="text" id="telefone1" placeholder="Telefone" required>
<input class="telefone-content" type="text" id="telefone2" placeholder="Telefone" required>
<input class="telefone-content" type="text" id="telefone3" placeholder="Telefone" required>
<input class="telefone-content" type="text" id="telefone4" placeholder="Telefone" required>
</div>
<div class="row">
<label for="email1">Email</label>
<input class="email-content" type="text" id="email1" placeholder="Email" required>
<input class="email-content" type="text" id="email2" placeholder="Email" required>
<input class="email-content" type="text" id="email3" placeholder="Email" required>
<input class="email-content" type="text" id="email4" placeholder="Email" required>
</div>
<div class="row">
<label for="categoria">Categorias</label>
<input class="categoria-content" type="text" id="categoria" placeholder="Informe as Categorias" required>
<label for="data_constituicao">Data Da Constituição</label>
<input class="data-content" type="date" id="data_constituicao" placeholder="Data da Constituição" required>
<label for="data_cvm">Data da CVM</label>
<input class="data-content" type="date" id="data_cvm" placeholder="Data do CVM" required>
</div>
<div class="row">
<label for="controlador">Controlador</label>
<input class="controlador-content" type="text" id="controlador" placeholder="Nome do Controlador" required>
<label for="cnpj_controlador">CNPJ</label>
<input class="cnpj-content" type="text" id="cnpj_controlador" placeholder="CNPJ" required>
</div>
</form>
</div>
</div>
This image link shows how I want it to be
https://www.figma.com/file/nuLJYzwr2LtoJxt4rPKDaI/Untitled?node-id=0%3A1
Just wrap label and input inside a div and add :
.row > div {
display: flex;
flex-direction: column;
}
Related
I need to do this only using flex but I am having some difficulty aligning my labels and input fields properly.This is what the end result is supposed to look like.
Any help would be appreciated!
<form>
<div class="details">
<label for="email">E-mail:</label>
<input type="email" id="email" name="email">
</div>
<div class="details">
<label for="tel">Telephone Number:</label>
<input type="tel" id="tel" name="tel">
</div>
<div class="details">
<label for="position">Position:</label>
<input type="text" id="position" name="position">
<input type="radio" name="availability" id="Part-Time" value="Part-Time">
<label for="radio">Part-Time</label>
<input type="radio" name="availability" id="Full-Time" value="Full-Time">
<label for="radio">Full-Time</label>
</div>
<div class="details">
<label for="date">Date:</label>
<input type="date" id="date" name="date">
<input type="checkbox" name="AM" id="AM" value="AM">
<label for="checkbox">AM</label>
<input type="checkbox" name="PM" id="PM" value="PM">
<label for="radio">PM</label>
</div>
<div class="details">
<label for="yearsofexperience">Years of Experience:</label>
<input type="text" id="yearsofexperience" name="yearsofexperience">
</div>
<div class="details">
</div>
<div class="details">
<label for="experience">Experience:</label>
<textarea name="experience" id="experience" rows="1" cols="20">Worked 5 years at Bayshore Veterinarian Services</textarea>
</div>
<div class="details">
<input type="submit" value="Apply Now">
</div>
</form>
I have tried all sorts of things but i cannot get them to line up. I have tried having two columns where column 1 contains the labels, while the other column contains the input field but i did not succeed.
I wrote some CSS to create the desired layout. It works without changing the provided HTML.
You can add the missing name input from the image though.
The .details > input:first-child selects the Apply Now button and set a margin-left: calc(25% + 6px), so it has a left space matching the labels and is align with other inputs.
You might as well consider using an actual <button> tag for submit though. If you do so later, you can change this selector to .details > button:first-child.
Hope this will help!
Example:
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
form {
width: 600px;
display: flex;
flex-direction: column;
gap: 9px;
padding: 30px;
}
.details {
display: flex;
justify-content: flex-start;
align-items: center;
gap: 6px;
}
.details > label:first-child {
width: 25%;
display: flex;
justify-content: flex-end;
}
.details > input#date {
margin-right: 30px;
}
.details > input:first-child {
margin-left: calc(25% + 6px);
padding: 3px 6px;
}
<form>
<div class="details">
<label for="email">E-mail:</label>
<input type="email" id="email" name="email" />
</div>
<div class="details">
<label for="tel">Telephone Number:</label>
<input type="tel" id="tel" name="tel" />
</div>
<div class="details">
<label for="position">Position:</label>
<input type="text" id="position" name="position" />
<input type="radio" name="availability" id="Part-Time" value="Part-Time" />
<label for="radio">Part-Time</label>
<input type="radio" name="availability" id="Full-Time" value="Full-Time" />
<label for="radio">Full-Time</label>
</div>
<div class="details">
<label for="date">Date:</label>
<input type="date" id="date" name="date" />
<input type="checkbox" name="AM" id="AM" value="AM" />
<label for="checkbox">AM</label>
<input type="checkbox" name="PM" id="PM" value="PM" />
<label for="radio">PM</label>
</div>
<div class="details">
<label for="yearsofexperience">Years of Experience:</label>
<input type="text" id="yearsofexperience" name="yearsofexperience" />
</div>
<div class="details"></div>
<div class="details">
<label for="experience">Experience:</label>
<textarea name="experience" id="experience" rows="1" cols="20">
Worked 5 years at Bayshore Veterinarian Services</textarea
>
</div>
<div class="details">
<input type="submit" value="Apply Now" />
</div>
</form>
I am attempting to align the two cells for the address input. The one that is inline I can shift, but the ones that are not I do know know how to shift right. If I could get some creative feed back I would appreciate it.
.EMBody {
position: relative;
background-color: navajowhite;
}
.EMSpace {
display: inline-block;
width: 100px;
}
.EMAdj {
display: inline-block;
margin-right: 20%;
}
input[type="text"] {
width: 60%;
}
<section class="EMBody">
<div>
<label class="EMSpace">Full Name:</label>
<input type="text" placeholder="Enter your name">
</div>
<div>
<label class="EMSpace">Address:</label>
<input type="text" placeholder="Street address">
<input type="text" class="EMAdj" placeholder="City">
<input type="text" class="EMAdj" placeholder="Zip">
</div>
<div>
<label class="EMSpace">Phone Number:</label>
<input type="text" placeholder="9999999999">
</div>
<div>
<label class="EMSpace">Email:</label>
<input type="text" placeholder="email#email.com">
</div>
<div>
<label class="EMSpace">Brief Message: </label>
<textarea cols="25" rows="5" class="message" placeholder="Please give a brief discription of your Iguana issues. Green or Spiny Tailed? In the attics, flowerbed, canal?"></textarea>
</div>
</section>
use nth-child :
.EMBody {
position: relative;
background-color: navajowhite;
}
.EMSpace {
display: inline-block;
width: 100px;
}
.EMAdj {
display: inline-block;
margin-right: 20%;
}
input[type="text"] {
width: 60%;
}
input:nth-child(3),input:nth-child(4)
{
margin-left:104px;
}
<section class="EMBody">
<div>
<label class="EMSpace">Full Name:</label>
<input type="text" placeholder="Enter your name">
</div>
<div>
<label class="EMSpace">Address:</label>
<input type="text" placeholder="Street address">
<input type="text" class="EMAdj" placeholder="City">
<input type="text" class="EMAdj" placeholder="Zip">
</div>
<div>
<label class="EMSpace">Phone Number:</label>
<input type="text" placeholder="9999999999">
</div>
<div>
<label class="EMSpace">Email:</label>
<input type="text" placeholder="email#email.com">
</div>
<div>
<label class="EMSpace">Brief Message: </label>
<textarea cols="25" rows="5" class="message" placeholder="Please give a brief discription of your Iguana issues. Green or Spiny Tailed? In the attics, flowerbed, canal?"></textarea>
</div>
</section>
The easiest fully responsive solution would be to use CSS-Grid. THis would allow you to cut the code down a lot.
simply use a 2 column layout and let the label for the address span 3 rows.
.EMBody {
display: grid;
grid-template-columns: min-content auto;
column-gap: 10px;
}
.EMBody {
white-space: nowrap;
}
.EMBody label:nth-of-type(2) {
grid-row: span 3;
}
<section class="EMBody">
<label class="EMSpace">Full Name:</label>
<input type="text" placeholder="Enter your name">
<label class="EMSpace">Address:</label>
<input type="text" placeholder="Street address">
<input type="text" class="EMAdj" placeholder="City">
<input type="text" class="EMAdj" placeholder="Zip">
<label class="EMSpace">Phone Number:</label>
<input type="text" placeholder="9999999999">
<label class="EMSpace">Email:</label>
<input type="text" placeholder="email#email.com">
<label class="EMSpace">Brief Message: </label>
<textarea cols="25" rows="5" class="message" placeholder="Please give a brief discription of your Iguana issues. Green or Spiny Tailed? In the attics, flowerbed, canal?"></textarea>
</section>
I have a parent div with 3 child divs inside. I need that each child div take one third of the screen and that all elements (text, button and input) inside of each divs are responsive by always being to the center of the child divs.
I could make in sort that each child divs takes one third of the screen but the elements aren't responsive and are diving themselves in two columns inside the child divs, like seen in the picture below:
Here is the code used:
input,
select,
textarea {
width: 100%;
padding: 6px;
border: 1px solid #ccc;
border-radius: 5px;
}
label {
padding: 12px 12px 12px 0;
display: inline-block;
}
.Order_Create_Ship_Stock>div {
width: 30%;
margin: 5px;
padding: auto;
display: inline-table;
border: solid;
}
.Order_Create,
.Order_Ship,
.Order_Store {
border-radius: 5px;
background-color: #f2f2f2;
padding: 10px;
display: table-cell;
}
#SubmitCreateOrder,
#SubmitShipOrder,
#SubmitStoreOrder {
cursor: pointer;
display: flex;
flex-direction: column;
}
<div id="OrderCreateShipStock" class="Order_Create_Ship_Stock">
<div id="OrderCreate" class="Order_Create">
<form onsubmit="App.createOrder(); return false">
<label for="BarcodeInput">
<span>Barcode</span>
<input name="BarcodeInput"id="Barcode" class="Barcorde" type="text" placeholder="Order's Barcode...">
</label>
<label for="OwnerInput">
<span>Owner</span>
<input name="OwnerInput" id="Owner" class="Owner" type="text" placeholder="Owner of the product...">
</label>
<label for="ProductListInput">
<span>Product list</span>
<input name="ProductListInput" id="ProductList" class="Product_List" type="text" placeholder="Product list of the order....">
</label>
<label for="ExpirationDateInput">
<span>Expiration date</span>
<input name="ExpirationDateInput" id="ExpirationDate" class="Expiration_Date" type="date">
</label>
<label for="TemperatureMinimalInput">
<span>Temperature minimal</span>
<input name="TemperatureMinimalInput" id="TemperatureMinimal" class="Temperature_Minimal" type="number" placeholder="Minimal temperature of order's environment...">
</label>
<label for="TemperatureMaximalInput">
<span>Temperature maximal</span>
<input name="TemperatureMaximalInput" id="TemperatureMaximal" class="Temperature_Maximal" type="number" placeholder="Maximal temperature of order's environment...">
</label>
<label for="IOTDeviceInput">
<span>IOT Device</span>
<select name="IOTDeviceInput" id="IOTDevice" class="IOT_Device">
<option value="">---Please select an IOT Device---</option>
</select>
</label>
<label for="FinalDestinationInput">
<span>Final destination</span>
<input name="FinalDestinationInput" id="FinalDestination" class="Final_Destination" type="text" placeholder="Order's final destination...">
</label>
<button id="SubmitCreateOrder" class="Submit_Create_Order" type="submit">Create Order</button>
</form>
</div>
<div id="OrderShip" class="Order_Ship">
<form onsubmit="App.ShipOrder(); return false">
<label for="OrderIDInput">
<span>OrderID</span>
<input name="OrderIDInput" id="OrderID" class="Order_ID" type="text" placeholder="Order's ID">
</label>
<label for="ActualLocationInput">
<span>Actual location</span>
<input name="ActualLocationInput" id="ActualLocation" class="Actual_Location_Input" type="text" placeholder="Order's actual location">
</label>
<label for="ActualTemperatureInput">
<span>Actual temperature</span>
<input name="ActualTemperatureInput" id="ActualTemperature" class="Actual_Temperature" type="text" placeholder="Order's actual environment temperature">
</label>
<label for="CurrentCounterpartyInput">
<span>Counterparty</span>
<input name="CurrentCounterpartyInput" id="CurrentCounterparty" class="Current_Counterparty" type="text" placeholder="Order's current counterparty">
</label>
<label for="IOTDeviceInput">
<span>IOT Device</span>
<select name="IOTDeviceInput" id="IOTDevice" class="IOT_Device_Input">
</select>
</label>
<label for="AnticipatedDateInput">
<span>Anticipated date</span>
<input name="AnticipatedDateInput" id="AnticipatedDate" class="Anticipated_Date" type="date">
</label>
<label for="DestinationInput">
<span>Destination</span>
<input name="DestinationInput" id="Destination" class="Destination_" type="text" placeholder="Order's destination">
</label>
<button id="SubmitShipOrder" class="Submit_Ship_Order" type="submit">Ship Order</button>
</form>
</div>
<div id="OrderStore" class="Order_Store">
<form onsubmit="App.storeOrder(); return false">
<label for="OrderIDInput">
<span>OrderID</span>
<input name="OrderIDInput" id="OrderID" class="Order_ID" type="text" placeholder="Order's ID">
</label>
<label for="ActualLocationInput">
<span>Actual location</span>
<input name="ActualLocationInput" id="ActualLocation" class="Actual_Location_Input" type="text" placeholder="Order's actual location">
</label>
<label for="ActualTemperatureInput">
<span>Actual temperature</span>
<input name="ActualTemperatureInput" id="ActualTemperature" class="Actual_Temperature" type="text" placeholder="Order's actual environment temperature">
</label>
<label for="CurrentCounterpartyInput">
<span>Counterparty</span>
<input name="CurrentCounterpartyInput" id="CurrentCounterparty" class="Current_Counterparty" type="text" placeholder="Order's current counterparty">
</label>
<label for="IOTDeviceInput">
<span>IOT Device</span>
<select name="IOTDeviceInput" id="IOTDevice" class="IOT_Device_Input">
<option value="">---Please select an IOT Device---</option>
</select>
</label>
<button id="SubmitStoreOrder" class="Submit_Store_Order" type="submit">Store Order</button>
</form>
</div>
</div>
While I was working I could somehow make in sort that the buttons remains in one column by using flexbox (flex-direction: column), but this method didn't work for the inputs and textarea...
So I would like to ask some help to make in sort that all elements inside these child divs remain in only one column please.
I thank in advance anybody who will take the time to help me.
For the buttons, adding margin: auto, centered any child will do the job and I add one more option to the first Button if you find useful to make it a full button.
Also for the container to be responsive, you can to set the parent the flex box. Then set all child with flex: 1 and use media queries to make it columns.
/* --- FOR THE CONTAINERS --- */
#OrderCreateShipStock {
display: flex;
}
.Order_Create_Ship_Stock>div {
margin: 5px;
border: solid;
flex: 1;
}
#media only screen and (max-width: 800px) {
#OrderCreateShipStock {
flex-wrap: wrap;
flex-direction: column;
}
}
/* --- BUTTON CENTERED --- */
#SubmitCreateOrder, #SubmitShipOrder, #SubmitStoreOrder {
display: flex;
margin: auto;
}
/* --- BUTTON FULL CENTERED TEXT --- */
#SubmitCreateOrder, #SubmitShipOrder, #SubmitStoreOrder {
width: 100%;
justify-content: center;
align-items: center;
}
input,
select,
textarea {
width: 100%;
padding: 6px;
border: 1px solid #ccc;
border-radius: 5px;
}
label {
padding: 12px 12px 12px 0;
display: inline-block;
}
#OrderCreateShipStock {
display: flex;
}
.Order_Create_Ship_Stock>div {
margin: 5px;
border: solid;
flex: 1;
}
.Order_Create,
.Order_Ship,
.Order_Store {
border-radius: 5px;
background-color: #f2f2f2;
padding: 10px;
display: table-cell;
}
#SubmitCreateOrder,
#SubmitShipOrder,
#SubmitStoreOrder {
display: flex;
margin: auto;
}
#SubmitCreateOrder {
width: 100%;
justify-content: center;
align-items: center;
}
#media only screen and (max-width: 500px) {
#OrderCreateShipStock {
flex-wrap: wrap;
flex-direction: column;
}
}
<div id="OrderCreateShipStock" class="Order_Create_Ship_Stock">
<div id="OrderCreate" class="Order_Create">
<form onsubmit="App.createOrder(); return false">
<label for="BarcodeInput">
<span>Barcode</span>
<input name="BarcodeInput"id="Barcode" class="Barcorde" type="text" placeholder="Order's Barcode...">
</label>
<label for="OwnerInput">
<span>Owner</span>
<input name="OwnerInput" id="Owner" class="Owner" type="text" placeholder="Owner of the product...">
</label>
<label for="ProductListInput">
<span>Product list</span>
<input name="ProductListInput" id="ProductList" class="Product_List" type="text" placeholder="Product list of the order....">
</label>
<label for="ExpirationDateInput">
<span>Expiration date</span>
<input name="ExpirationDateInput" id="ExpirationDate" class="Expiration_Date" type="date">
</label>
<label for="TemperatureMinimalInput">
<span>Temperature minimal</span>
<input name="TemperatureMinimalInput" id="TemperatureMinimal" class="Temperature_Minimal" type="number" placeholder="Minimal temperature of order's environment...">
</label>
<label for="TemperatureMaximalInput">
<span>Temperature maximal</span>
<input name="TemperatureMaximalInput" id="TemperatureMaximal" class="Temperature_Maximal" type="number" placeholder="Maximal temperature of order's environment...">
</label>
<label for="IOTDeviceInput">
<span>IOT Device</span>
<select name="IOTDeviceInput" id="IOTDevice" class="IOT_Device">
<option value="">---Please select an IOT Device---</option>
</select>
</label>
<label for="FinalDestinationInput">
<span>Final destination</span>
<input name="FinalDestinationInput" id="FinalDestination" class="Final_Destination" type="text" placeholder="Order's final destination...">
</label>
<button id="SubmitCreateOrder" class="Submit_Create_Order" type="submit">Create Order</button>
</form>
</div>
<div id="OrderShip" class="Order_Ship">
<form onsubmit="App.ShipOrder(); return false">
<label for="OrderIDInput">
<span>OrderID</span>
<input name="OrderIDInput" id="OrderID" class="Order_ID" type="text" placeholder="Order's ID">
</label>
<label for="ActualLocationInput">
<span>Actual location</span>
<input name="ActualLocationInput" id="ActualLocation" class="Actual_Location_Input" type="text" placeholder="Order's actual location">
</label>
<label for="ActualTemperatureInput">
<span>Actual temperature</span>
<input name="ActualTemperatureInput" id="ActualTemperature" class="Actual_Temperature" type="text" placeholder="Order's actual environment temperature">
</label>
<label for="CurrentCounterpartyInput">
<span>Counterparty</span>
<input name="CurrentCounterpartyInput" id="CurrentCounterparty" class="Current_Counterparty" type="text" placeholder="Order's current counterparty">
</label>
<label for="IOTDeviceInput">
<span>IOT Device</span>
<select name="IOTDeviceInput" id="IOTDevice" class="IOT_Device_Input">
</select>
</label>
<label for="AnticipatedDateInput">
<span>Anticipated date</span>
<input name="AnticipatedDateInput" id="AnticipatedDate" class="Anticipated_Date" type="date">
</label>
<label for="DestinationInput">
<span>Destination</span>
<input name="DestinationInput" id="Destination" class="Destination_" type="text" placeholder="Order's destination">
</label>
<button id="SubmitShipOrder" class="Submit_Ship_Order" type="submit">Ship Order</button>
</form>
</div>
<div id="OrderStore" class="Order_Store">
<form onsubmit="App.storeOrder(); return false">
<label for="OrderIDInput">
<span>OrderID</span>
<input name="OrderIDInput" id="OrderID" class="Order_ID" type="text" placeholder="Order's ID">
</label>
<label for="ActualLocationInput">
<span>Actual location</span>
<input name="ActualLocationInput" id="ActualLocation" class="Actual_Location_Input" type="text" placeholder="Order's actual location">
</label>
<label for="ActualTemperatureInput">
<span>Actual temperature</span>
<input name="ActualTemperatureInput" id="ActualTemperature" class="Actual_Temperature" type="text" placeholder="Order's actual environment temperature">
</label>
<label for="CurrentCounterpartyInput">
<span>Counterparty</span>
<input name="CurrentCounterpartyInput" id="CurrentCounterparty" class="Current_Counterparty" type="text" placeholder="Order's current counterparty">
</label>
<label for="IOTDeviceInput">
<span>IOT Device</span>
<select name="IOTDeviceInput" id="IOTDevice" class="IOT_Device_Input">
<option value="">---Please select an IOT Device---</option>
</select>
</label>
<button id="SubmitStoreOrder" class="Submit_Store_Order" type="submit">Store Order</button>
</form>
</div>
</div>
Just found the error, I just needed to add to label and not input, select the following:
display: flex;
flex-direction: column;
Hello in Firefox the form is offset. Have absolutly no idea why, because it works fine with chrome and internet-explorer. I'm using Firefox version 56.0 (32-Bit).
The form is designed with flexbox.
enter image description here
<form class="form wow fadeIn">
<div class="flex">
<div class="flexcontainer_new">
<label for="name" >Dein Name: </label><br>
<input class="input" type="text" name="name" id="name" ><br>
</div>
<div class="flexcontainer_new margin_left_60" >
<label for="email" >Deine Email: </label><br>
<input class="input" type="text" name="email" id="email" ><br>
</div>
</div>
<div class="flexcontainer_new_2.0">
<label class="margin-bottom_20" for="description" >Erzähl mir von deinem Projekt: </label><br>
<textarea></textarea>
</div>
<input href="" type="submit" value="Senden">
</form>
.flexcontainer_new{
display:flex;
margin: 100px auto 0;
width:750px;
height: 100px;
flex-direction: column;
}
.flexcontainer_new_2.0{
display:flex;
margin: 0 auto;
width:100px;
flex-direction: column;
}
I am wanting to make a label on a form that is much longer than the other labels in the form appear on multiple lines. I then want to align the inputs to the labels on the colons of the labels.
Here is a picture of the current set up:
Basically, I need Releasse Date to appear as
Release Date
(YYYY-MM-DD): [input box]
HTML Code:
<form action="http://localhost/songadded.php" method="post" id="songform">
<h4>Add a New Song</h4>
<div>
<label for="name">Name:</label>
<input type="text" name="name" size="30" value=""/>
</div>
<div>
<label for="artist">Artist:</label>
<input type="text" name="artist" size="30" value=""/>
</div>
<div>
<label for="album">Album:</label>
<input type="text" name="album" size="30" value=""/>
</div>
<div>
<label for="genre">Genre:</label>
<input type="text" name="genre" size="30" value=""/>
</div>
<div>
<label for="release_date" id="rdlabel">Release Date (YYYY-MM-DD):</label>
<input type="text" name="release_date" size="30" value="" id="rdinput"/>
</div>
<div>
<label for="bpm">BPM:</label>
<input type="text" name="bpm" maxlength="3" value=""/>
</div>
<div id="songsubmit">
<input type="submit" name="submit" value="Add Song"/>
</div>
</form>
CSS Code:
#songform {
margin: 20px;
}
label {
float: left;
width: 250px;
margin-top: 20px;
clear: right;
}
input{
margin-top: 20px;
}
#songsubmit {
margin-left: 80px;
}
Use display:inline-block and vertical-align:bottom. No floats or absolute positioning needed.
#songform {
margin: 20px;
}
#songform > div {
position: relative;
margin-top: 20px;
}
label {
display:inline-block;
width: 250px;
vertical-align:bottom;
}
#songsubmit {
margin-left: 80px;
}
<form action="http://localhost/songadded.php" method="post" id="songform">
<h4>Add a New Song</h4>
<div>
<label for="name">Name:</label>
<input type="text" name="name" size="30" value=""/>
</div>
<div>
<label for="artist">Artist:</label>
<input type="text" name="artist" size="30" value=""/>
</div>
<div>
<label for="album">Album:</label>
<input type="text" name="album" size="30" value=""/>
</div>
<div>
<label for="genre">Genre:</label>
<input type="text" name="genre" size="30" value=""/>
</div>
<div>
<label for="release_date" id="rdlabel">Release Date<br>(YYYY-MM-DD):</label>
<input type="text" name="release_date" size="30" value="" id="rdinput"/>
</div>
<div>
<label for="bpm">BPM:</label>
<input type="text" name="bpm" maxlength="3" value=""/>
</div>
<div id="songsubmit">
<input type="submit" name="submit" value="Add Song"/>
</div>
</form>
I've made a fiddle with code for your case: http://jsfiddle.net/862xc2j1/
You can solve it with adding clear:left to each div wrapper for each form field block.
<div class="form-item">
<label for="name">Name:</label>
<input type="text" name="name" size="30" value=""/>
</div>
.form-item {
clear: left;
}
To get this alignment next to the colon, you can use absolute positioning. Here is a working example - I made a few more changes to get it to work:
#songform {
margin: 20px;
}
#songform > div {
position: relative;
margin-top: 20px;
}
#songform > div:after {
/* Clearfix */
content:"";
display:table;
clear:both;
}
#songform > div > input {
position: absolute;
bottom: 0;
}
label {
float: left;
width: 250px;
clear: right;
}
#songsubmit {
margin-left: 80px;
}
<form action="http://localhost/songadded.php" method="post" id="songform">
<h4>Add a New Song</h4>
<div>
<label for="name">Name:</label>
<input type="text" name="name" size="30" value=""/>
</div>
<div>
<label for="artist">Artist:</label>
<input type="text" name="artist" size="30" value=""/>
</div>
<div>
<label for="album">Album:</label>
<input type="text" name="album" size="30" value=""/>
</div>
<div>
<label for="genre">Genre:</label>
<input type="text" name="genre" size="30" value=""/>
</div>
<div>
<label for="release_date" id="rdlabel">Release Date<br>(YYYY-MM-DD):</label>
<input type="text" name="release_date" size="30" value="" id="rdinput"/>
</div>
<div>
<label for="bpm">BPM:</label>
<input type="text" name="bpm" maxlength="3" value=""/>
</div>
<div id="songsubmit">
<input type="submit" name="submit" value="Add Song"/>
</div>
</form>