Left and right alignment inside div - html

I am trying to design the layout in the below screenshot
I tried to implement the same in fiddle
http://jsfiddle.net/NNLct/1/
<div id="CorpDealerSearch" >
<div class="left"> DealerName </div>
<div class="left"> Region </div>
<div class="left"> DealerCode </div>
<div class="left"> Area </div>
<div class="left">
<input type="text"/>
</div>
<div class="left">
<input type="text"/>
</div>
<div class="left">
<input type="text"/>
</div>
<div class="left">
<input type="text"/>
</div>
</div>
Please help in suggesting proper css to get the design

Have a look at this FIDDLE
HTML
<div class='table'>
<div class='row'>
<div class='cell'>DealerName
<input type='text' />DealerCode
<input type='text' />
</div>
<div class='cell'>Region
<input type='text' />Area
<input type='text' />
</div>
</div>
</div>
CSS
body{
width:100%;
padding:0;
margin:0;
box-sizing:border-box;
}
.table {
display:table;
width:100%;
}
.row {
display:table-row;
}
.cell {
display:table-cell;
padding-right:20px;
}
input {
display:block;
width:100%;
}

Try something else:
http://jsfiddle.net/Ta6Qk/
HTML
<div class="main">
<div>
<label>Data</label>
<input type="text" value="">
</div>
<div>
<label>Data</label>
<input type="text" value="">
</div>
<div>
<label>Data</label>
<input type="text" value="">
</div>
<div>
<label>Data</label>
<input type="text" value="">
</div>
</div>
and CSS
.main {
width: 400px;
position: relative;
}
.main div {
border: none;
display: inline-block;
width: 44%;
margin-right: 3%;
}
input {
width: 100%;
}
label {
display:block
}

You have to include label and input in the same div:
http://jsfiddle.net/NNLct/5/
Don't forget you can also use label tags to associate the text to the related input.
<div id="CorpDealerSearch" >
<div class="left">
DealerName <input type="text"/>
</div>
<div class="left">
Region <input type="text"/>
</div>
<div class="left">
DealerCode <input type="text"/>
</div>
<div class="left">
Area <input type="text"/>
</div>
</div>
CSS:
.left
{
float:left;
}

Going by your existing markup, here is a : DEMO
Float the elements and after every 2 element, clear the floats, as simple as that!! :)
CSS
.left {
float:left
}
.clr{clear:both}
HTML
<div id="CorpDealerSearch">
<div class="left">DealerName
<br />
<input type="text" />
</div>
<div class="left">Region
<br />
<input type="text" />
</div>
<div class="clr"></div>
<div class="left">DealerCode
<br />
<input type="text" />
</div>
<div class="left">DealerCode
<br />
<input type="text" />
</div>
</div>

See this fiddle:
http://jsfiddle.net/NNLct/16/
Using display:table; display:table-row; display:cell;

Here's the fiddle:Check this
Here's the HTML Code:
<div id="container">
<div id="left" class="left">
<div id="top-left" class="innerdiv">
<div id="lbl-tl">
Dealer Name:
</div>
<div id="txt-tl">
<input type="text" style="width: 90%;" />
</div>
</div>
<div id="bottom-left" class="innerdiv">
<div id="lbl-bl">
Dealer Code:
</div>
<div id="txt-bl">
<input type="text" style="width: 90%;" />
</div>
</div>
</div>
<div id="right" class="right" >
<div id="top-right" class="innerdiv">
<div id="lbl-tr">
Region:
</div>
<div id="txt-tr">
<input type="text" style="width: 90%;" />
</div>
</div>
<div id="bottom-right" class="innerdiv">
<div id="lbl-br">
Area:
</div>
<div id="txt-br">
<input type="text" style="width: 90%;" />
</div>
</div>
</div>
</div>
And here's the CSS:
*
{
margin: 0px;
padding: 0px;
}
#container
{
width: 700px;
min-height: 150px;
}
.left
{
width: 49%;
min-height: 150px;
float: left;
}
.right
{
min-height: 150px;
width: 49%;
float: right;
}
.innerdiv
{
height: 75px;
}

First I would change the html to:
HTML
<div id="CorpDealerSearch" >
<div>
<label for="dealerName">DealerName</label>
<input type="text" id="dealerName" name="dealerName">
<label for="Region">Region</label>
<input type="text" id="Region" name="Region">
</div>
<div>
<label for="DealerCode">DealerCode</label>
<input type="text" id="DealerCode" name="DealerCode">
<label for="Area">Area</label>
<input type="text" id="Area" name="Area">
</div>
</div>
And the css would be:
CSS
#CorpDealerSearch label, input{
float:left;
clear:both;
}
#CorpDealerSearch div{
display:block;
float:left;
width:200px;
}
hope this will help.

Related

How to create multiple rows which contains two text boxes and labels above them in html/css?

I want to create three rows. In each row I want to have two textboxes with labels above them. Right now, I have this html code:
.firstRow, .secondRow, .thirdRow {
display: inline-block;
}
label, .textBox {
display: block;
}
<div class="firstRow">
<label for="name1">Name1</label>
<input class="textBox" formControlName="name1" />
<label for="name2">Name2</label>
<input class="textBox" formControlName="name2" />
</div>
<div class="secondRow">
<label for="name3">Name3</label>
<input class="textBox" formControlName="name3" />
<label for="name4">Name4</label>
<input class="textBox" formControlName="name4" />
</div>
<div class="thirdRow">
<label for="name5">Name5</label>
<input class="textBox" formControlName="name5" />
<label for="name6">Name6</label>
<input class="textBox" formControlName="name6" />
</div>
The outcome is in this link:
https://jsfiddle.net/Lcav5xje/
What should I change?
Here is the snippet using simple display:flex;
also no need to add separate class for every row
.row {
display: flex;
}
.form-grp {
margin: 10px
}
.form-grp label {
display:block;
}
<div class="row">
<div class="form-grp">
<label for="name1">Name1</label>
<input class="textBox" formControlName="name1" />
</div>
<div class="form-grp">
<label for="name2">Name2</label>
<input class="textBox" formControlName="name2" />
</div>
</div>
<div class="row">
<div class="form-grp">
<label for="name3">Name3</label>
<input class="textBox" formControlName="name3" />
</div>
<div class="form-grp">
<label for="name4">Name4</label>
<input class="textBox" formControlName="name4" />
</div>
</div>
<div class="row">
<div class="form-grp">
<label for="name5">Name5</label>
<input class="textBox" formControlName="name5" />
</div>
<div class="form-grp">
<label for="name6">Name6</label>
<input class="textBox" formControlName="name6" />
</div>
</div>
You can use grid to align the items.
example:
.row {
display: block;
}
.grid {
display: grid;
grid-template-rows: 1fr 1fr; /*Two columns*/
grid-auto-flow: column /*to align the input under the label*/;
justify-content: start; /*sticked to the left*/
grid-gap: 0 10px; /*horizontal space between inputs*/
}
<div class="row">
<div class="grid">
<label for="name1">Name1</label>
<input class="textBox" formControlName="name1" />
<label for="name2">Name2</label>
<input class="textBox" formControlName="name2" />
</div>
<div class="row">
<div class="grid">
<label for="name3">Name3</label>
<input class="textBox" formControlName="name3" />
<label for="name4">Name4</label>
<input class="textBox" formControlName="name4" />
</div>
</div>
<div class="row">
<div class="grid">
<label for="name5">Name5</label>
<input class="textBox" formControlName="name5" />
<label for="name6">Name6</label>
<input class="textBox" formControlName="name6" />
</div>
</div>
Try this code..
Demo
.firstRow,
.secondRow,
.thirdRow {
display: inherit;
}
.inner {
display: inline-block;
vertical-align: top;
}
<div class="firstRow">
<div class="inner">
<label for="name1">Name1</label>
<input class="textBox" formcontrolname="name1">
</div>
<div class="inner">
<label for="name2">Name2</label>
<input class="textBox" formcontrolname="name2">
</div>
</div>

HTML Form, How to Vertically Align & Center Input Fields?

I have an HTML Form, with the input fields already centered, but they are not vertically aligned together.
I would like to have all of the labels and inputs vertically aligned so that all the labels are on the same vertical line, and all the inputs are on the same vertical line.
So far all I have is the fields inside a div:
<div class="container" align="center">
#formContainer{
width:40%;
margin:auto;
}
#formC{
width:100%;
}
.rows{
width:100%;
display:block;
}
.column{
width:100%;
display:inline-block;
}
.theLabels{
width:30%
float:left;
}
.theInputs{
width:60%;
float:right;
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="formContainer">
<form id="formC">
<div class="rows">
<div class="column">
<label class="theLabels">
URL:
</label>
<input class="theInputs" type="text"/>
</div>
<div class="column">
<label class="theLabels">
Code Base:
</label>
<input class="theInputs" type="text"/>
</div>
<div class="column">
<label class="theLabels">
Email:
</label>
<input class="theInputs" type="email"/>
</div>
</div>
</form>
</div>
</body>
</html>
If you want 2 columns in a row you should change width:100% in column class to width:48% or make another class with width:48%. Hope it helps
Are you using Bootstrap?
Make a main div and place everything inside it.. like
<div class="container h-100">
<div class="row h-100 justify-content-center align-items-center">
<form class="col-12">
<div class="form-group">
<label for="formGroupExampleInput">Example label</label>
<input type="text" class="form-control" id="formGroupExampleInput" placeholder="Example input">
</div>
<div class="form-group">
<label for="formGroupExampleInput2">Another label</label>
<input type="text" class="form-control" id="formGroupExampleInput2" placeholder="Another input">
</div>
</form>
</div>
</div>
See HERE
A workout for this would be to have a main which holds the entire form, and then wrap every label in a element with a fixed width, you can then do the same with the input elements.
Fiddle:
https://jsfiddle.net/7mnxwdgv/14/
<html>
<head>
<style type="text/css">
div.container {
width: 350px;
padding: 15px;
margin: 50px auto 0px auto;
clear: both;
overflow: hidden;
}
div.container span.label-holder {
display: block;
width: calc(25% - 10px);
float: left;
padding: 5px;
}
div.container span.input-holder {
display: block;
width: calc(75% - 10px);
float: left;
padding: 5px;
}
div.container span.input-holder input[type="text"]{
width: 100%;
}
</style>
</head>
<body>
<div class="container">
<form>
<span class="label-holder"><label for="url">URL</label></span>
<span class="input-holder"><input type="text" id="url" name="url" placeholder="url" /></span>
<span class="label-holder"><label for="code-base">Code Base</label></span>
<span class="input-holder"><input type="text" id="code-base" name="Code-Base" placeholder="Code Base" /></span>
<span class="label-holder"><label for="from">From</label></span>
<span class="input-holder"><input type="text" id="from" name="from" placeholder="From" /></span>
<span class="label-holder"><label for="to">to</label></span>
<span class="input-holder"><input type="text" id="to" name="to" placeholder="To" /></span>
<span class="label-holder"><label for="email">Email</label></span>
<span class="input-holder"><input type="text" id="email" name="email" placeholder="Your Email" /></span>
<span class="label-holder"><label for="app-serv">Application Servers</label></span>
<span class="input-holder">
<select name="app-serv" id="app-serv">
<option value="Incent">Incent</option>
</select>
</span>
</form>
</div>
</body>
</html>

Some of my floated DIVs don't align in Chrome and Firefox [duplicate]

This question already has answers here:
Floated elements of variable height push siblings down
(3 answers)
What methods of ‘clearfix’ can I use?
(29 answers)
Closed 4 years ago.
I would like to ask for some help with my problem. I have a large form, and I've decided to make it 2 columns for easier readability.
I have a container DIV, and there are DIVs inside it sectioning it to 2 parts. I've left aligned the inside DIVs to float next to each other.
In IE11, it (mostly) works, but for some reason, it doesn't work like I intended on other browsers: there are "gaps" between some of the DIVs.
Here's the code:
.container {
width: 100%;
font-size: 80%;
}
.contentwrapper {
width: 80%;
margin: 0 auto;
}
.Box {
border: black 1px dotted;
padding: 1em;
margin: 0 auto 3% 0;
min-width: 55em;
overflow: hidden;
}
.Box .Header {
background-color: #f7f7f7;
font-weight: bold;
font-size: 110%;
padding-left: 5px;
padding-right: 5px;
}
.Section {
width: 45%;
float: left;
padding: 5px;
display:inline-block;
background-color: red;
vertical-align: bottom;
}
.Section .Question {
width: 32%;
float: left;
}
.Section .Answer {
text-align: left;
width: 65%;
float: left;
}
.Section .help {
width: 15px;
float:right;
background-image: url("images/helpbutton.png");
background-repeat: no-repeat;
}
.Section .Sectioninput, .Section select {
width: 95%
}
.Section .smallInput {
width: 5em;
}
.Section #orszagS{width: 28%}
.Section #countryT{width: 48%}
.Section #cityname{width: 50%}
<div class="container">
<div class="contentwrapper">
<fieldset class="Box">
<legend class="Header">Alapadatok</legend>
<div class="Section">
<div class="Question"><label for="countryT">Country</label></div>
<div class="Answer">
<select id="countryS" class="smallInput">
<option value="hungary">Hungary</option>
<option value="other">Other</option>
</select>
<input type="text" class="Sectioninput required" id="countryT" name="countryT" value="Hungary" disabled />
</div>
<div class="help"><br /></div>
</div>
<div class="Section">
<div class="Question"><label for="county">County</label></div>
<div class="Answer">
<select name="county" id="county" class="required">
<option value=""> </option>
<option value="1">Option 1</option>
<option value="2">Option 12</option>
</select>
</div>
<div class="help"><br /></div>
</div>
<div class="Section">
<div class="Question"><label for="cityname">City</label></div>
<div class="Answer">
<input type="text" class="smallInput required" name="zipcode" value="" placeholder="Zip Code"/>
<input type="text" class="required" id="cityname" name="cityname" value="" placeholder="City" />
</div>
<div class="help"><br /></div>
</div>
<div class="Section">
<div class="Question"><label for="location">Location</label></div>
<div class="Answer required">
<select name="location" id="location">
<option value=""> </option>
<option value="1">Outside</option>
<option value="0">Inside</option>
</select>
</div>
<div class="help"><br /></div>
</div>
<div class="Section">
<div class="Question"><label for="bnumber">Number</label></div>
<div class="Answer">
<input type="text" class="Sectioninput required" name="bnumber" id="bnumber" value="" />
</div>
<div class="help"><br /></div>
</div>
<div class="Section">
<div class="Question"><label for="relnumbers">Related Numbers</label></div>
<div class="Answer">
<input type="text" class="Sectioninput" name="relnumbers" id="relnumbers" value="" />
</div>
<div class="help"><br /></div>
</div>
<div class="Section">
<div class="Question"><label for="address">Address</label></div>
<div class="Answer">
<input type="text" class="Sectioninput" name="address" id="address" value="" />
</div>
<div class="help"><br /></div>
</div>
<div class="Section">
<div class="Question"><label for="name">Name</label></div>
<div class="Answer">
<input type="text" class="Sectioninput required" name="name" id="name" value="" />
</div>
<div class="help"><br /></div>
</div>
<div class="Section">
<div class="Question"><label for="function">Function</label></div>
<div class="Answer">
<input type="text" class="Sectioninput" name="function" id="function" value="" />
</div>
<div class="help"><br /></div>
</div>
</fieldset>
</div>
</div>
I made my inside DIVs with a red background, so it's easier to see the white gap. What can I do to make 2 DIVs next to each other in each row?
Thanks in advance!

Space text boxes after their label

With style sheets I float name, email left and nickname and school right but I would like their text boxes to start at the same point. How can I achieve this with CSS?
<div id="container" align="center">
<div id="name">Name:
<input id="name_text" type="text">
</div>
<div id="nickname">Nickname:
<input id="nickname_text" type="text">
</div>
<div id="email">Email Address:
<input id="email_text" type="text">
</div>
<div id="school">School:
<input id="school_text" type="text">
</div>
</div>
You have to use this way:
There should be <label> to make sure when the user clicks on the label text, it focuses on the respective input.
The <strong> tag has a display: inline-block making it easy to set the width.
You don't need so many ids.
You need to give name attribute to all the <input /> fields.
label strong {display: inline-block; width: 150px; text-align: left; margin: 0 0 10px;}
<div id="container" align="center">
<div id="name">
<label>
<strong>Name:</strong>
<input id="name_text" type="text" />
</label>
</div>
<div id="nickname">
<label>
<strong>Nickname:</strong>
<input id="nickname_text" type="text" />
</label>
</div>
<div id="email">
<label>
<strong>Email Address:</strong>
<input id="email_text" type="text" />
</label>
</div>
<div id="school">
<label>
<strong>School:</strong>
<input id="school_text" type="text" />
</label>
</div>
</div>
li {
list-style-type: none;
}
li p {
display: inline-block;
width: 120px;
text-align: left;
font-family: "Times New Roman";
font-style: oblique;
font-size: 14px;
}
<div id="container" align="center">
<ul>
<li>
<p>Name:</p>
<input type="text">
</li>
<li>
<p>Nickname:</p>
<input type="text">
</li>
<li>
<p>Email Address:</p>
<input type="text">
</li>
<li>
<p>School:</p>
<input type="text">
</li>
</ul>
</div>
Codepen
A little modification,copy this code and check it.
<html>
<head>
<style>
label strong {display: inline-block; width: 150px; text-align: left; margin: 0 0 10px;}
</style>
</head>
<body>
<center>
<div id="Holder" style="width:50%;">
<div id="L_div" style="float:left;">
<div id="container" align="center">
<div id="name">
<label>
<strong>Name:</strong>
<input id="name_text" type="text" />
</label>
</div>
<div id="email">
<label>
<strong>Email Address:</strong>
<input id="email_text" type="text" />
</label>
</div>
</div>
</div>
<div id="R_div" style="float:right;">
<div id="nickname">
<label>
<strong>Nickname:</strong>
<input id="nickname_text" type="text" />
</label>
</div>
<div id="school">
<label>
<strong>School:</strong>
<input id="school_text" type="text" />
</label>
</div>
</div>
</div>
</div>
</center>
</body>
</html>
If you are a fresher in css use this site W3school for guidence
Regds

3 column form with 3rd column spanning vertically

I'm trying to find a way to have a form that displays the fields horizontally rather than vertically....with the exception of the last column. I'd like that to span vertically. Here's the code I have for getting the 2 columns the way I'd like them:
<html>
<head>
<style type="text/css">
.display-label, .editor-label
{
margin: 1em 0 0 0;
display: block;
width: 300px;
}
.display-field, .editor-field
{
margin: 0.5em 0 0 0;
display: block;
width: 300px;
}
.sameline-wrapper
{
float: left;
display: inline;
}
.newline
{
display: block;
clear: both;
}
</style>
</head>
<body>
<form action="test.html" method="post">
<div class="newline">
<div class="sameline-wrapper">
<div class="display-label">
Here is a field:
</div>
<div class="display-field">
<input type="text" id="t1" style="width: 100px;" />
</div>
</div>
<div class="sameline-wrapper">
<div class="display-label">
Here is a second field:
</div>
<div class="display-field">
<input type="text" id="t2" style="width: 100px;" />
</div>
</div>
</div>
<div class="newline">
<div class="sameline-wrapper">
<div class="display-label">
Here is a third field:
</div>
<div class="display-field">
<input type="text" id="t3" style="width: 100px;" />
</div>
</div>
<div class="sameline-wrapper">
<div class="display-label">
Here is a fourth field:
</div>
<div class="display-field">
<input type="text" id="t4" style="width: 100px;" />
</div>
</div>
</div>
<div class="newline">
<div class="sameline-wrapper">
<div class="display-label">
Here is a fifth field:
</div>
<div class="display-field">
<input type="text" id="Text1" style="width: 100px;" />
</div>
</div>
<div class="sameline-wrapper">
<div class="display-label">
Here is a sixth field:
</div>
<div class="display-field">
<input type="text" id="Text2" style="width: 100px;" />
</div>
</div>
</div>
<div class="newline">
<div class="sameline-wrapper">
<div class="display-label">
Here is a seventh field:
</div>
<div class="display-field">
<input type="text" id="Text3" style="width: 100px;" />
</div>
</div>
<div class="sameline-wrapper">
<div class="display-label">
Here is a eigth field:
</div>
<div class="display-field">
<input type="text" id="Text4" style="width: 100px;" />
</div>
</div>
</div>
</form>
</body>
</html>
What I'm trying to accomplish now is to have a 3rd column to the left that spans the entire height of the other rows. The idea is to have a textarea control in there and it all look uniform. I've added this image to help see what I'm trying to do:
and here's a fiddle:
3 Column Form
I just don't know how to get that 3rd column to line up to the left of the others and to be the same height (vertically) as the other rows. Any help is greatly appreicated!
Rearrange your html to specify one div for each column like this:
<html>
<head>
<style type="text/css">
.newspaperCol
{
float: left;
width: 33%;
}
.display-label
{
margin: 1em 0 0 0;
display: block;
}
.display-field
{
margin: 0.5em 0 0 0;
display: block;
}
</style>
</head>
<body>
<div class="newspaperCol">
<label class="display-label">Field 1:</label>
<input class="display-field" type="text" id="text1">
<br />
<label class="display-label">Field 3:</label>
<input class="display-field" type="text" id="text3">
<br />
<label class="display-label">Field 5:</label>
<input class="display-field" type="text" id="text5">
<br />
<label class="display-label">Field 7:</label>
<input class="display-field" type="text" id="text7">
</div>
<div class="newspaperCol">
<label class="display-label">Field 2:</label>
<input class="display-field" type="text" id="text2">
<br />
<label class="display-label">Field 4:</label>
<input class="display-field" type="text" id="text4">
<br />
<label class="display-label">Field 6:</label>
<input class="display-field" type="text" id="text6">
<br />
<label class="display-label">Field 8:</label>
<input class="display-field" type="text" id="text8">
</div>
<div class="newspaperCol">
<label class="display-label">Notes:</label>
<textarea rows="17" cols="30" id="notestext"></textarea>
</div>
</body>
</html>
EDIT:
I re-read your question and updated my answer using more of your original code. I think you're missing some HTML for the notes elements. Try adding the colLeft and colRight css classes and the associated "div" elements shown below.
<html>
<head>
<style type="text/css">
.colLeft
{
float: left;
width: 66%;
}
.colRight
{
float: left;
width: 33%;
}
.display-label, .editor-label
{
margin: 1em 0 0 0;
display: block;
width: 300px;
}
.display-field, .editor-field
{
margin: 0.5em 0 0 0;
display: block;
width: 300px;
}
.sameline-wrapper
{
float: left;
display: inline;
}
.newline
{
display: block;
clear: both;
}
</style>
</head>
<body>
<form action="test.html" method="post">
<div class="colLeft">
<div class="newline">
<div class="sameline-wrapper">
<div class="display-label">
Here is a field:
</div>
<div class="display-field">
<input type="text" id="t1" style="width: 100px;" />
</div>
</div>
<div class="sameline-wrapper">
<div class="display-label">
Here is a second field:
</div>
<div class="display-field">
<input type="text" id="t2" style="width: 100px;" />
</div>
</div>
</div>
<div class="newline">
<div class="sameline-wrapper">
<div class="display-label">
Here is a third field:
</div>
<div class="display-field">
<input type="text" id="t3" style="width: 100px;" />
</div>
</div>
<div class="sameline-wrapper">
<div class="display-label">
Here is a fourth field:
</div>
<div class="display-field">
<input type="text" id="t4" style="width: 100px;" />
</div>
</div>
</div>
<div class="newline">
<div class="sameline-wrapper">
<div class="display-label">
Here is a fifth field:
</div>
<div class="display-field">
<input type="text" id="Text1" style="width: 100px;" />
</div>
</div>
<div class="sameline-wrapper">
<div class="display-label">
Here is a sixth field:
</div>
<div class="display-field">
<input type="text" id="Text2" style="width: 100px;" />
</div>
</div>
</div>
<div class="newline">
<div class="sameline-wrapper">
<div class="display-label">
Here is a seventh field:
</div>
<div class="display-field">
<input type="text" id="Text3" style="width: 100px;" />
</div>
</div>
<div class="sameline-wrapper">
<div class="display-label">
Here is a eigth field:
</div>
<div class="display-field">
<input type="text" id="Text4" style="width: 100px;" />
</div>
</div>
</div>
</div>
<div class="colRight">
<label>Notes:</label>
<textarea rows="15" cols="30" id="notestext"></textarea>
</div>
</form>
</body>
</html>