Hello everyone I have form which contains few different group of fields. In order to keep them together I used div elements and make them act like table elements. I used this method to avoid table elements inside of the form. In other hand some people said this approach is the same basically since I made div's to act like a table. To be honest I'm not sure if this is the best option. Here is example of my code.
form {
width: 820px;
}
form.frmLayout fieldset {
border: #ccc 2px solid;
margin: 10px;
border-radius:3px;
}
form.frmLayout legend {
font-weight: bold;
background-color: #c8e2db;
border-radius:3px;
padding: 3px;
border: #ccc 2px solid;
}
form.frmLayout label {
float: left;
font-weight: bold;
display: block;
}
form.frmLayout input[type=text] {
text-align: left;
background-color: #c8e2db;
}
div.formItem {
margin-top: 5px;
margin-bottom: 5px;
margin-left: 5px;
margin-right: 5px;
padding-top: 5px;
padding-bottom: 5px;
background-repeat: repeat-x;
clear: both;
border-bottom: #ccc 2px dashed;
}
div.formItem:last-child{
border-bottom: none;
}
div.formTbl {
display: table;
width: 100%;
}
div.frRow {
display: table-row;
text-align: left;
}
div.frCell {
display: table-cell;
padding-top: 2px;
padding-bottom: 2px;
padding-left: 0px;
padding-right: 0px;
text-align: center;
}
div.frCell span {
font-weight: bold;
}
<form name="myForm" id="myForm" method="POST" action="#" class="frmLayout">
<input type="hidden" name="frmhs_id" id="frmhs_id" value="" />
<fieldset>
<legend>My Form</legend>
<div class="formItem">
<div class="formTbl">
<div class="frRow">
<div class="frCell" style="width:60%;">
</div>
<div class="frCell" style="width:40%;">
<div class="formTbl">
<div class="frRow">
<div class="frCell" style="width:40%;">
<span>Acoustic Reflex Thresholds</span>
</div>
</div>
<div class="frRow">
<div class="frCell" style="width:10%;">
<span>500</span>
</div>
<div class="frCell" style="width:10%;">
<span>1000</span>
</div>
<div class="frCell" style="width:10%;">
<span>2000</span>
</div>
<div class="frCell" style="width:10%;">
<span>4000</span>
</div>
</div>
<div class="frRow">
<div class="frCell" style="width:10%;">
<input type="text" name="frmhs_td6" id="frmhs_td6" value="" size="4" maxlength="4" />
</div>
<div class="frCell" style="width:10%;">
<input type="text" name="frmhs_td7" id="frmhs_td7" value="" size="4" maxlength="4" />
</div>
<div class="frCell" style="width:10%;">
<input type="text" name="frmhs_td8" id="frmhs_td8" value="" size="4" maxlength="4" />
</div>
<div class="frCell" style="width:10%;">
<input type="text" name="frmhs_td9" id="frmhs_td9" value="" size="4" maxlength="4" />
</div>
</div>
<div class="frRow">
<div class="frCell" style="width:10%;">
<input type="text" name="frmhs_td15" id="frmhs_td15" value="" size="4" maxlength="4" />
</div>
<div class="frCell" style="width:10%;">
<input type="text" name="frmhs_td16" id="frmhs_td16" value="" size="4" maxlength="4" />
</div>
<div class="frCell" style="width:10%;">
<input type="text" name="frmhs_td17" id="frmhs_td17" value="" size="4" maxlength="4" />
</div>
<div class="frCell" style="width:10%;">
<input type="text" name="frmhs_td18" id="frmhs_td18" value="" size="4" maxlength="4" />
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="formItem">
<div style="float:left;">
<span><input type="submit" name="frmSubmit" id="frmhdSubmit" value="Submit"></span>
</div>
<div style="float:right;">
<span id="MsgFrm"></span>
</div>
</div>
</fieldset>
</form>
As you can see in my example above title Acoustic Reflex Thresholds is not on the center. Also I think that affects first set of div cells to change the width. I'm wondering how I can make title to go over entire length of div cell? If anyone knows how this can be fixed or is there better way to do this please let me know. Thanks in advance.
One of the limitations of css table layout is that you cannot simulate colspan, so the cells are going to be sized the same as the rest in its "column" even if its only 1 column in the row (as you can see with your "Acoustic Reflex Thresholds" heading).
What you can do is make the heading a table-caption instead of a row and that works, as you can see if you run the updated code snippet below.
There are 2 changes required:
CSS: Add the new class for the table caption
div.frCaption{
display: table-caption;
caption-side: top;
text-align: center;
font-weight: bold;
}
HTML: change the table-row to table-caption
In the row that contains with you "Acoustic Reflex Thresholds" heading:
Change the class from frRow to frCaption
Remove the frCell div altogether
[...right column...]
<div class="frCell" style="width:40%;">
<div class="formTbl">
<div class="frCaption ">
<span>Acoustic Reflex Thresholds</span>
</div>
<div class="frRow">
[... rest of rows...]
form {
width: 820px;
}
form.frmLayout fieldset {
border: #ccc 2px solid;
margin: 10px;
border-radius:3px;
}
form.frmLayout legend {
font-weight: bold;
background-color: #c8e2db;
border-radius:3px;
padding: 3px;
border: #ccc 2px solid;
}
form.frmLayout label {
float: left;
font-weight: bold;
display: block;
}
form.frmLayout input[type=text] {
text-align: left;
background-color: #c8e2db;
}
div.formItem {
margin-top: 5px;
margin-bottom: 5px;
margin-left: 5px;
margin-right: 5px;
padding-top: 5px;
padding-bottom: 5px;
background-repeat: repeat-x;
clear: both;
border-bottom: #ccc 2px dashed;
}
div.formItem:last-child{
border-bottom: none;
}
div.formTbl {
display: table;
width: 100%;
}
div.frRow {
display: table-row;
text-align: left;
}
div.frCell {
display: table-cell;
padding-top: 2px;
padding-bottom: 2px;
padding-left: 0px;
padding-right: 0px;
text-align: center;
}
div.frCell span {
font-weight: bold;
}
div.frCaption{
display: table-caption;
caption-side: top;
text-align: center;
font-weight: bold;
}
<form name="myForm" id="myForm" method="POST" action="#" class="frmLayout">
<input type="hidden" name="frmhs_id" id="frmhs_id" value="" />
<fieldset>
<legend>My Form</legend>
<div class="formItem">
<div class="formTbl">
<div class="frRow">
<div class="frCell" style="width:60%;">
</div>
<div class="frCell" style="width:40%;">
<div class="formTbl">
<div class="frCaption ">
<span>Acoustic Reflex Thresholds</span>
</div>
<div class="frRow">
<div class="frCell" style="width:10%;">
<span>500</span>
</div>
<div class="frCell" style="width:10%;">
<span>1000</span>
</div>
<div class="frCell" style="width:10%;">
<span>2000</span>
</div>
<div class="frCell" style="width:10%;">
<span>4000</span>
</div>
</div>
<div class="frRow">
<div class="frCell" style="width:10%;">
<input type="text" name="frmhs_td6" id="frmhs_td6" value="" size="4" maxlength="4" />
</div>
<div class="frCell" style="width:10%;">
<input type="text" name="frmhs_td7" id="frmhs_td7" value="" size="4" maxlength="4" />
</div>
<div class="frCell" style="width:10%;">
<input type="text" name="frmhs_td8" id="frmhs_td8" value="" size="4" maxlength="4" />
</div>
<div class="frCell" style="width:10%;">
<input type="text" name="frmhs_td9" id="frmhs_td9" value="" size="4" maxlength="4" />
</div>
</div>
<div class="frRow">
<div class="frCell" style="width:10%;">
<input type="text" name="frmhs_td15" id="frmhs_td15" value="" size="4" maxlength="4" />
</div>
<div class="frCell" style="width:10%;">
<input type="text" name="frmhs_td16" id="frmhs_td16" value="" size="4" maxlength="4" />
</div>
<div class="frCell" style="width:10%;">
<input type="text" name="frmhs_td17" id="frmhs_td17" value="" size="4" maxlength="4" />
</div>
<div class="frCell" style="width:10%;">
<input type="text" name="frmhs_td18" id="frmhs_td18" value="" size="4" maxlength="4" />
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="formItem">
<div style="float:left;">
<span><input type="submit" name="frmSubmit" id="frmhdSubmit" value="Submit"></span>
</div>
<div style="float:right;">
<span id="MsgFrm"></span>
</div>
</div>
</fieldset>
</form>
Related
In the default CSS code for radio buttonn, it is gray when it is not selected and is blue when it is selected:
I however need it to be black in both states. Thus, I have overriden SCSS for radio buttons. Here comes my code:
HTML:
<div class="col-md-2 col-sm-6">
<div class="row">
<div class="col-md-12">
<label>Earlier experience in this field?</label>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="radio">
<label><input type="radio" formControlName="earlierExperience" value="1">Yes</label>
</div>
</div>
<div class="col-md-6">
<div class="radio">
<label><input type="radio" formControlName="earlierExperience" value="0">No</label>
</div>
</div>
</div>
</div>
CSS:
input[type='radio']:after {
width: 15px;
height: 15px;
border-radius: 50%;
top: -2px;
left: -1px;
position: relative;
background-color:white;
display: inline-block;
visibility: visible;
border: 1px solid black;
}
input[type='radio']:checked:after {
border: 4.5px solid black;
}
The problem with this code is that the small circle in the middle of the checked button is not shown anymore:
Can you help me with this?
You can use the new property accent-color which sets the colour for the input. Broswer support is limited to Chrome and Firefox at the moment so you will create fallbacks for other browsers.
input {accent-color: black;}
input {
accent-color: black;
}
<div class="col-md-2 col-sm-6">
<div class="row">
<div class="col-md-12">
<label>Earlier experience in this field?</label>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="radio">
<label><input type="radio" formControlName="earlierExperience" value="1">Yes</label>
</div>
</div>
<div class="col-md-6">
<div class="radio">
<label><input type="radio" formControlName="earlierExperience" value="0">No</label>
</div>
</div>
</div>
</div>
For solution, you can use property filter in css.
input[type='radio'] {
filter: grayscale(100%) contrast(200%);
}
input[type='radio'] {
filter: grayscale(100%) contrast(200%);
}
<div class="col-md-2 col-sm-6">
<div class="row">
<div class="col-md-12">
<label>Earlier experience in this field?</label>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="radio">
<label>
<input
type="radio"
formControlName="earlierExperience"
value="1"
/>Yes
</label>
</div>
</div>
<div class="col-md-6">
<div class="radio">
<label>
<input
type="radio"
formControlName="earlierExperience"
value="0"
/>No
</label>
</div>
</div>
</div>
</div>
Custom solution with box-shadow, pseudo-element and input binding to label
.radio {
margin-left: 0.125em;
}
.radio label {
position: relative;
padding-left: 1.5em;
cursor: pointer;
}
.radio label::after {
content: '';
width: 1em;
height: 1em;
position: absolute;
top: 0;
left: 0.25em;
border-radius: 50%;
box-shadow: inset 0 0 0 2px black;
}
input[type='radio'] {
position: absolute;
visibility: hidden;
}
input[type='radio']:checked~label::after {
box-shadow: inset 0 0 0 2px black, inset 0 0 0 4px white, inset 0 0 0 10px rgb(0, 0, 0);
}
<div class="col-md-2 col-sm-6">
<div class="row">
<div class="col-md-12">
<label>Earlier experience in this field?</label>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="radio">
<input id="yes" type="radio" name="radio" formControlName="earlierExperience" value="1" />
<label for="yes"> Yes </label>
</div>
</div>
<div class="col-md-6">
<div class="radio">
<input id="no" type="radio" name="radio" formControlName="earlierExperience" value="0" />
<label for="no"> No </label>
</div>
</div>
</div>
</div>
I tried the following:
input[type="checkbox"]:disabled {
background-color:blue;
}
but it's not working.
form{
border:solid 2px darkblue;
width:60%;
padding-bottom:3%;
margin:0 auto;
}
#container{
display:flex;
flex-wrap:wrap;
justify-content:center;
margin:0 auto;
}
.info{
margin:2% 3%;
}
.contact{
display:flex;
flex-direction:column;
margin-bottom:1%;
width:50%;
font-size:1.5vw;
}
.alerts{
width:100%;
font-size:1.5vw;
text-align:left;
margin-left:3%;
color:red;
}
p.alerts{
text-align:center;
margin-top:1%;
margin-bottom:5%;
margin-left:0;
}
.hidden{
visibility:hidden;
}
.row{
display:flex;
justify-content:space-between;
width:80%;
margin:0 auto;
}
.col{
display:flex;
flex-direction:column;
}
#skippers{
display:flex;
flex-direction:row;
Justify-content:center;
align-items:center;
margin-bottom:3%;
}
.skippers{
margin: 0 3%;
}
input[type="checkbox"]:disabled {
background-color:blue;
}
input[type='submit']{
color:white;
background-color: blue;
font-weight:bold;
}
<h1>Registration</h1>
<form action='register.php' method='POST'>
<h2>Enter contact info</h2>
<div id='container'>
<div class='contact'>
<input class='info' type='text' name='fname' placeholder='first name'>
<span class='alerts hidden'>Please enter your first name</span>
</div>
<div class='contact'>
<input class='info' type='text' name='lname' placeholder='last name'>
<span class='alerts hidden'>Please enter your last name</span>
</div>
<div class='contact'>
<input class='info' type='tel' name='phone' placeholder='mobile phone number'>
<span class='alerts hidden'>Please enter your mobile phone number</span>
</div>
<div class='contact'>
<input class='info' type='email' name='email' placeholder='email'>
<span class='alerts hidden'>Please enter your email</span>
</div>
<div class='contact'>
<input class='info' type='password' name='password' placeholder='password'>
<span class='alerts hidden'>Please enter your password</span>
</div>
<div class='contact'>
<input class='info' type='password' name='confirm' placeholder='confirm password'>
<span class='alerts hidden'>Please enter your password</span>
</div>
</div>
<h2>Days available to sail</h2>
<div class='row'>
<div class='col'>
<label for="MO">M</label>
<input class='dow' type="checkbox" name="MO">
</div>
<div class='col'>
<label for="TU">T</label>
<input class='dow' type="checkbox" name="TU">
</div>
<div class='col'>
<label for="WE">W</label>
<input class='dow' type="checkbox" name="WE">
</div>
<div class='col'>
<label for="TH">T</label>
<input class='dow' type="checkbox" name="TH">
</div>
<div class='col'>
<label for="FR">F</label>
<input class='dow' type="checkbox" name="FR">
</div>
<div class='col'>
<label for="SA">S</label>
<input class='dow' type="checkbox" name="SA">
</div>
<div class='col'>
<label for="SU">S</label>
<input class='dow' type="checkbox" name="SU">
</div>
</div>
<p class='alerts hidden'>Please select at least 1 day</p>
<h2>Select Skippers</h2>
<div id='skippers'>
<p class='skippers'>David Cross</p>
<input class='skippers' type='checkbox' checked required disabled style="background-color:red">
</div>
<input type='submit' value = 'SUBMIT' name='mySubmit'>
</fom>
</div>
<script src="../public/js/register.js" type="text/javascript"></script>
</body>
</html>
I'm proposing a different solution, which preserves accessibility and still allows for the styling of your choice.
Instead of using the disabled attribute on the checkbox, which ostensibly makes it impossible to override the background-color, add aria-disabled="true", which allows for visitors on screen-readers to correctly identify the element as disabled.
<input class='skippers' aria-disabled="true" type='checkbox' checked required>
<!-- ~~~~~~~~~~~~~~~~~~~ -->
As for the majority of visitors viewing our form elements inside a more common browser, we can ignore all clicks on the checkbox.
input[type="checkbox"][aria-disabled="true"] {
background-color: blue;
pointer-events: none;
}
form {
border: solid 2px darkblue;
width: 60%;
padding-bottom: 3%;
margin: 0 auto;
}
#container {
display: flex;
flex-wrap: wrap;
justify-content: center;
margin: 0 auto;
}
.info {
margin: 2% 3%;
}
.contact {
display: flex;
flex-direction: column;
margin-bottom: 1%;
width: 50%;
font-size: 1.5vw;
}
.alerts {
width: 100%;
font-size: 1.5vw;
text-align: left;
margin-left: 3%;
color: red;
}
p.alerts {
text-align: center;
margin-top: 1%;
margin-bottom: 5%;
margin-left: 0;
}
.hidden {
visibility: hidden;
}
.row {
display: flex;
justify-content: space-between;
width: 80%;
margin: 0 auto;
}
.col {
display: flex;
flex-direction: column;
}
#skippers {
display: flex;
flex-direction: row;
Justify-content: center;
align-items: center;
margin-bottom: 3%;
}
.skippers {
margin: 0 3%;
}
input[type="checkbox"]:disabled {
background-color: blue;
}
input[type='submit'] {
color: white;
background-color: blue;
font-weight: bold;
}
input[type="checkbox"][aria-disabled="true"] {
background-color: blue;
pointer-events: none;
}
<h1>Registration</h1>
<form action='register.php' method='POST'>
<h2>Enter contact info</h2>
<div id='container'>
<div class='contact'>
<input class='info' type='text' name='fname' placeholder='first name'>
<span class='alerts hidden'>Please enter your first name</span>
</div>
<div class='contact'>
<input class='info' type='text' name='lname' placeholder='last name'>
<span class='alerts hidden'>Please enter your last name</span>
</div>
<div class='contact'>
<input class='info' type='tel' name='phone' placeholder='mobile phone number'>
<span class='alerts hidden'>Please enter your mobile phone number</span>
</div>
<div class='contact'>
<input class='info' type='email' name='email' placeholder='email'>
<span class='alerts hidden'>Please enter your email</span>
</div>
<div class='contact'>
<input class='info' type='password' name='password' placeholder='password'>
<span class='alerts hidden'>Please enter your password</span>
</div>
<div class='contact'>
<input class='info' type='password' name='confirm' placeholder='confirm password'>
<span class='alerts hidden'>Please enter your password</span>
</div>
</div>
<h2>Days available to sail</h2>
<div class='row'>
<div class='col'>
<label for="MO">M</label>
<input class='dow' type="checkbox" name="MO">
</div>
<div class='col'>
<label for="TU">T</label>
<input class='dow' type="checkbox" name="TU">
</div>
<div class='col'>
<label for="WE">W</label>
<input class='dow' type="checkbox" name="WE">
</div>
<div class='col'>
<label for="TH">T</label>
<input class='dow' type="checkbox" name="TH">
</div>
<div class='col'>
<label for="FR">F</label>
<input class='dow' type="checkbox" name="FR">
</div>
<div class='col'>
<label for="SA">S</label>
<input class='dow' type="checkbox" name="SA">
</div>
<div class='col'>
<label for="SU">S</label>
<input class='dow' type="checkbox" name="SU">
</div>
</div>
<p class='alerts hidden'>Please select at least 1 day</p>
<h2>Select Skippers</h2>
<div id='skippers'>
<p class='skippers'>David Cross</p>
<input class='skippers' aria-disabled="true" type='checkbox' checked required>
</div>
<input type='submit' value='SUBMIT' name='mySubmit'>
</fom>
</div>
<script src="../public/js/register.js" type="text/javascript"></script>
</body>
</html>
It's actually not that you can't style the :disabled state of a checkbox. It's more that you can't style much on a checkbox input at all. You'll see if I do the same style, but remove the :disabled state, the regular checkboxes are still the default color (on most browsers). The size is applied, but not the background-color.
input[type=checkbox]
{
width: 50px;
height: 50px;
background-color: red;
}
<input type="checkbox"/>
This is entirely up to the developer of the browser to implement, and as such it varies widely between all of them, but you can expect many CSS properties to be ineffective on a checkbox.
The typical solution to a problem like this is to implement your own custom checkbox element. At its core it's quite simple, having only a single boolean state that changes when you click on it.
Further reading
I have 4 columns and I need separate each column with borders. It looks like now:
How It should be (red/blue colors just for example):
Problem Is that I don't have any div for columns, I generating rows inside <li> </li> so 4 inputs inside <li> </li> is 1 row:
<form class="form-style-9">
<h2>Personal details</h2>
<ul>
<div id="personal-details">
<li>
<div class="test">
<label for="Rank">Rank</label>
<input id="Rank" type="text" name="Rank" class="field-style field-split25 align-left" placeholder="Rank" />
</div>
<div class="test">
<label for="RankApplied">Rank Applied</label>
<input id="RankApplied" type="text" name="RankApplied" class="field-style field-split25 align-left" placeholder="Rank Applied" />
</div>
<div class="test">
<label for="Vesselstype">Vessel's type</label>
<input id="Vesselstype" type="text" name="Vesselstype" class="field-style field-split25 align-left" placeholder="Vessel's type" />
</div>
<div class="test">
<label for="datepicker2">Date Applied</label>
<input id="datepicker2" type="date" name="datepicker2" class="field-style field-split25-4 align-left" placeholder="Date Applied" />
</div>
</li>
<li>
<div class="test">
<label for="fname">First Name</label>
<input id="fname" type="text" name="fname" class="field-style field-split25 align-left" placeholder="First Name" />
</div>
<div class="test">
<label for="nationality">Nationality</label>
<input id="nationality" type="text" name="nationality" class="field-style field-split25 align-left" placeholder="Nationality" />
</div>
<div class="test">
<label for="height">Height</label>
<input id="height" type="text" name="height" class="field-style field-split25 align-left" placeholder="Height" />
</div>
<div class="test">
<label for="na">Nearest airport</label>
<input id="na" type="text" name="na" class="field-style field-split25-4 align-left" placeholder="Nearest airport" />
</div>
</li>
<li>
<div class="test">
<label for="sname">Surename</label>
<input id="sname" type="text" name="sname" class="field-style field-split25 align-left" placeholder="Surename" />
</div>
<div class="test">
<label for="noc">No. of children</label>
<input id="noc" type="number" name="noc" class="field-style field-split25 align-left" placeholder="No. of children" />
</div>
<div class="test">
<label for="weight">Weight</label>
<input id="weight" type="number" name="weight" class="field-style field-split25 align-left" placeholder="Weight" />
</div>
<div class="test4">
<label for="languages">Languages</label>
<input id="languages" type="text" name="languages" class="field-style field-split25-4 align-left" placeholder="Languages" />
</div>
</li>
<li>
<div class="test">
<label for="datepicker">Date of Birth</label>
<input id="datepicker" type="date" name="datepicker" class="field-style field-split25 align-left" placeholder="Date of Birth" />
</div>
<div class="test">
<label for="nok">Next of kin</label>
<input id="nok" type="text" name="nok" class="field-style field-split25 align-left" placeholder="Next of kin" />
</div>
<div class="test">
<label for="coe">Color of eyes</label>
<input id="coe" type="text" name="coe" class="field-style field-split25 align-left" placeholder="Color of eyes" />
</div>
<div class="test4">
<label for="english">English</label>
<input id="english" type="text" name="english" class="field-style field-split25-4 align-left" placeholder="English" />
</div>
</li>
<li>
<div class="test">
<label for="pob">Place of Birth</label>
<input id="pob" type="text" name="pob" class="field-style field-split25-4 align-left" placeholder="Place of Birth" />
</div>
<div class="test">
<label for="nonok">Name of Next of Kin</label>
<input id="nonok" type="text" name="nonok" class="field-style field-split25 align-left" placeholder="Name of Next of Kin" />
</div>
<div class="test">
<label for="coh">Color of hair</label>
<input id="coh" type="text" name="coh" class="field-style field-split25 align-left" placeholder="Color of hair" />
</div>
<div class="test4">
<label for="german">German</label>
<input id="german" type="text" name="german" class="field-style field-split25-4 align-left" placeholder="German" />
</div>
</li>
<li>
<div class="test">
<label for="HomeAddress">Home Address</label>
<input id="HomeAddress" type="text" name="HomeAddress" class="field-style field-split25 align-left" placeholder="Home Address" />
</div>
<div class="test">
<label for="aonok">Address of Next of Kin</label>
<input id="aonok" type="text" name="aonok" class="field-style field-split25 align-left" placeholder="Address of Next of Kin" />
</div>
<div class="test">
<label for="os">Overall size</label>
<input id="os" type="text" name="os" class="field-style field-split25 align-left" placeholder="Overall size" />
</div>
<div class="test4">
<label for="spain">Spain</label>
<input id="spain" type="text" name="spain" class="field-style field-split25-4 align-left" placeholder="Spain" />
</div>
</li>
<li>
<div class="test">
<label for="TelNo">Telephone No.</label>
<input id="TelNo" type="text" name="TelNo" class="field-style field-split25 align-left" placeholder="Telephone No." />
</div>
<div class="test">
<label for="TelNo">Telephone No.</label>
<input id="TelNo" type="text" name="TelNo" class="field-style field-split25 align-left" placeholder="Telephone No." />
</div>
<div class="test">
<label for="sz">Shoe size</label>
<input id="sz" type="text" name="sz" class="field-style field-split25 align-left" placeholder="Shoe size" />
</div>
<div class="test4">
<label for="BankDetails">Bank Details</label>
<input id="BankDetails" type="text" name="BankDetails" class="field-style field-split25-4 align-left" placeholder="Bank Details" />
</div>
</li>
</div>
Have you any ideas how can I achieve that? Here is FIDDLE
If to keep your existing markup, here is an option (though you might need to adjust the values a little)
To be noted, having a <div id="personal-details"> as a direct child of ul is invalid markup and should be removed. You can put the id on the ul instead.
Updated fiddle
ul {
position: relative;
}
ul li:first-child .test:before {
content: ' ';
position: absolute;
display: block;
border: 1px solid red;
top: 0;
left: 0;
width: 23.5%;
height: 100%;
}
ul li:first-child .test:nth-child(2):before {
left: calc(23.5% + 1px);
width: 24%;
border: 1px solid blue;
}
ul li:first-child .test:nth-child(3):before {
left: calc(47.5% + 1px);
width: 24%;
}
ul li:first-child .test:nth-child(4):before {
left: calc(71.5% + 1px);
border: 1px solid blue;
}
If you strongly need to keep it as row-wise, you have the option of using absolutely positioned, divs.
#personal-details{
position: relative;
}
ul{
list-style: none;
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
li{
width: 25%;
}
.parent{
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
}
.borders{
display: flex;
justify-content: space-between;
height: 40px;
}
.border{
border: 1px solid red;
width: 25%;
}
<div id="personal-details">
<ul>
<li>this is first</li>
<li>this is second</li>
<li>this is third</li>
<li>this is forth</li>
<li>this is first</li>
<li>this is second</li>
<li>this is third</li>
<li>this is forth</li>
</ul>
<div class="parent">
<div class="borders">
<div class="border"></div>
<div class="border"></div>
<div class="border"></div>
<div class="border"></div>
</div>
</div>
</div>
Note1
Please note that you should not put divs directly inside ul so this is incorrect:
<ul>
<div>
<li>Item</li>
<li>Item</li>
<li>Item</li>
</div>
</ul>
Note2
That would be a better practice if you produce them, column-wise, so that way you don't need to monkey with your CSS.
Desired markup
<ul id="personal-details">
<li>
<ul class="column">
<li>Rank</li>
<li>First name</li>
<li>Surname</li>
<li>Date of Birth</li>
<li>Place of Birth</li>
<li> ... </li>
<li> ... </li>
</ul>
</li>
<li>
<ul class="column">
<li>Rank</li>
<li>Nationality</li>
<li>No. of children</li>
<li>Next of kin</li>
<li>Name of Next of kin</li>
<li> ... </li>
<li> ... </li>
</ul>
</li>
<li> ... </li>
<li> ... </li>
</ul>
Solution
ul{
list-style: none;
}
#personal-details{
margin: auto;
display: flex;
justify-content: space-between;
}
#personal-details > li{
padding: 20px;
border: 1px solid red;
}
.column{
padding: 0;
text-align: center;
}
<ul id="personal-details">
<li>
<ul class="column">
<li>
<label for="Rank">Rank</label>
<input type="text" name="Rank" placeholder="Rank" />
</li>
<li>
<label for="Firstname">First name</label>
<input type="text" name="Firstname" placeholder="Firstname" />
</li>
<li>
<label for="Surname">Surname</label>
<input type="text" name="Surname" placeholder="Surname" />
</li>
<li>
<label for="Rank">Date of Birth</label>
<input type="text" name="DateofBirth" placeholder="DateofBirth" />
</li>
<li>
<label for="PlaceofBirth">Place of Birth</label>
<input type="text" name="PlaceofBirth" placeholder="Place of Birth" />
</li>
<li> ... </li>
<li> ... </li>
</ul>
</li>
<li>
<ul class="column">
<li>
<label for="RankApplied">Rank Applied</label>
<input type="text" name="RankApplied" placeholder="RankApplied" />
</li>
<li>
<label for="Nationality">Nationality</label>
<input type="text" name="Nationality" placeholder="Nationality" />
</li>
<li>
<label for="NoOfChildren">No. Of Children</label>
<input type="text" name="NoOfChildren" placeholder="NoOfChildren" />
</li>
<li>
<label for="NextOfKin">Next Of Kin</label>
<input type="text" name="NextOfKin" placeholder="NextOfKin" />
</li>
<li>
<label for="NameOfNextOfKin">Name of Next of kin</label>
<input type="text" name="NameOfNextOfKin" placeholder="NameOfNextOfKin" />
</li>
<li> ... </li>
<li> ... </li>
</ul>
</li>
<li>
<ul class="column">
<li>
<label for="Rank">Rank</label>
<input type="text" name="Rank" placeholder="Rank" />
</li>
<li>
<label for="Firstname">First name</label>
<input type="text" name="Firstname" placeholder="Firstname" />
</li>
<li>
<label for="Surname">Surname</label>
<input type="text" name="Surname" placeholder="Surname" />
</li>
<li>
<label for="Rank">Date of Birth</label>
<input type="text" name="DateofBirth" placeholder="DateofBirth" />
</li>
<li>
<label for="PlaceofBirth">Place of Birth</label>
<input type="text" name="PlaceofBirth" placeholder="Place of Birth" />
</li>
<li> ... </li>
<li> ... </li>
</ul>
</li>
<li>
<ul class="column">
<li>
<label for="RankApplied">Rank Applied</label>
<input type="text" name="RankApplied" placeholder="RankApplied" />
</li>
<li>
<label for="Nationality">Nationality</label>
<input type="text" name="Nationality" placeholder="Nationality" />
</li>
<li>
<label for="NoOfChildren">No. Of Children</label>
<input type="text" name="NoOfChildren" placeholder="NoOfChildren" />
</li>
<li>
<label for="NextOfKin">Next Of Kin</label>
<input type="text" name="NextOfKin" placeholder="NextOfKin" />
</li>
<li>
<label for="NameOfNextOfKin">Name of Next of kin</label>
<input type="text" name="NameOfNextOfKin" placeholder="NameOfNextOfKin" />
</li>
<li> ... </li>
<li> ... </li>
</ul>
</li>
</ul>
You can try to change that in following way.
<form class="form-style-9 clearfix">
<h2>Personal details</h2>
<ul>
<div id="personal-details">
<div class="col clearfix">
<div class="test">
<label for="Rank">Rank</label>
<input id="Rank" type="text" name="Rank" class="field-style field-split25 align-left" placeholder="Rank" />
</div>
<div class="test">
<label for="fname">First Name</label>
<input id="fname" type="text" name="fname" class="field-style field-split25 align-left" placeholder="First Name" />
</div>
<div class="test">
<label for="sname">Surename</label>
<input id="sname" type="text" name="sname" class="field-style field-split25 align-left" placeholder="Surename" />
</div>
<div class="test">
<label for="pob">Place of Birth</label>
<input id="pob" type="text" name="pob" class="field-style field-split25-4 align-left" placeholder="Place of Birth" />
</div>
</div>
<div class="col clearfix">
<div class="test">
<label for="RankApplied">Rank Applied</label>
<input id="RankApplied" type="text" name="RankApplied" class="field-style field-split25 align-left" placeholder="Rank Applied" />
</div>
<div class="test">
<label for="nationality">Nationality</label>
<input id="nationality" type="text" name="nationality" class="field-style field-split25 align-left" placeholder="Nationality" />
</div>
<div class="test">
<label for="noc">No. of children</label>
<input id="noc" type="number" name="noc" class="field-style field-split25 align-left" placeholder="No. of children" />
</div>
</div>
<div class="col clearfix">
<div class="test">
<label for="RankApplied">Rank Applied</label>
<input id="RankApplied" type="text" name="RankApplied" class="field-style field-split25 align-left" placeholder="Rank Applied" />
</div>
<div class="test">
<label for="nationality">Nationality</label>
<input id="nationality" type="text" name="nationality" class="field-style field-split25 align-left" placeholder="Nationality" />
</div>
<div class="test">
<label for="noc">No. of children</label>
<input id="noc" type="number" name="noc" class="field-style field-split25 align-left" placeholder="No. of children" />
</div>
</div>
<div class="col clearfix">
<div class="test">
<label for="RankApplied">Rank Applied</label>
<input id="RankApplied" type="text" name="RankApplied" class="field-style field-split25 align-left" placeholder="Rank Applied" />
</div>
<div class="test">
<label for="nationality">Nationality</label>
<input id="nationality" type="text" name="nationality" class="field-style field-split25 align-left" placeholder="Nationality" />
</div>
<div class="test">
<label for="noc">No. of children</label>
<input id="noc" type="number" name="noc" class="field-style field-split25 align-left" placeholder="No. of children" />
</div>
</div>
</form>
Blockquote
.form-style-9{
background: #FAFAFA;
padding: 30px;
margin: 50px auto;
box-shadow: 1px 1px 25px rgba(0, 0, 0, 0.35);
border-radius: 10px;
border: 6px solid #305A72;
}
.form-style-9 ul{
padding:0;
margin:0;
list-style:none;
}
.form-style-9 ul li{
display: block;
margin-bottom: 1.25%;
min-height: 58px;
}
.form-style-9 ul li .field-style{
box-sizing: border-box;
padding: 8px;
outline: none;
border: 1px solid #B0CFE0;
}
.form-style-9 ul li .field-style:focus{
box-shadow: 0 0 5px #B0CFE0;
border:1px solid #B0CFE0;
}
.form-style-9 ul li .field-split{
width: 49%;
}
.form-style-9 ul li .field-split25{
/* float: left;
width: 24%;
margin-right: 1.25%;*/
height: 40px;
}
.form-style-9 ul li .field-split25-4{
/*float: left;
width: 24%;
margin-right: 0;*/
height: 40px;
}
.form-style-9 ul li .field-full{
width: 100%;
}
.form-style-9 ul li input.align-left{
/*float:left;*/
}
.form-style-9 ul li input.align-right{
float:right;
}
.form-style-9 ul li textarea{
width: 100%;
height: 100px;
}
.form-style-9 ul li input[type="button"],
.form-style-9 ul li input[type="submit"] {
box-shadow: inset 0px 1px 0px 0px #3985B1;
background-color: #216288;
border: 1px solid #17445E;
display: inline-block;
cursor: pointer;
color: #FFFFFF;
padding: 8px 18px;
text-decoration: none;
font: 12px Arial, Helvetica, sans-serif;
}
.form-style-9 ul li input[type="button"]:hover,
.form-style-9 ul li input[type="submit"]:hover {
background: linear-gradient(to bottom, #2D77A2 5%, #337DA8 100%);
background-color: #28739E;
}
.formcol{
float: left;
padding: 2px;
}
.formcol label {
font-weight: bold;
display:block;
}
ul {
margin: 0;
padding: 0;
list-style-type: none;
}
.test {
margin-right: 1.25%;
margin-bottom: 1.25%;
}
.image-div {
margin-right: 4%;
float:right;
width: 200px;
height: 200px;
}
.image-upload {
float:right;
width: 100%;
margin-right: 1.25%;
margin-bottom: 1.25%;
}
.image-preview {
float:right;
width: 150px;
height: 150px;
margin-right: 1.25%;
margin-bottom: 1.25%;
position:relative;
border: 1px solid #B0CFE0;
}
.test4 {
float:left;
width: 23%;
margin-right: 0;
margin-bottom: 1.25%;
}
.test-label {
width: 23%;
margin-right: 1.25%;
margin-bottom: 0px;
padding:0px;
font-weight: bold;
}
.test-label1 {
width: 23%;
margin-right: 1.25%;
margin-bottom: 0px;
padding:0px;
}
.removeRow{
height:auto;
width:auto;
max-width:12px;
max-height:12px;
}
.div-format-30 {
width: 90%;
margin-right: 1.25%;
margin-bottom: 0;
margin-top: 1.25%;
border: 1px solid #B0CFE0;
}
.div-format-30 td{
margin-top:20px;
float:left;
width: 90%;
margin-right: 1.25%;
margin-bottom: 0;
margin-top: 1.25%;
border: 1px solid #B0CFE0;
}
.split33 {
float:left;
width: 28%;
margin-right: 1.25%;
margin-bottom: 1.25%;
}
.split33right {
float:right;
width: 23%;
margin-right: 0;
margin-bottom: 1.25%;
}
.div-format {
font-size:12px;
float:left;
width: 23%;
margin-right: 1.25%;
margin-bottom: 1.25%;
border: 1px solid #B0CFE0;
}
.test4 {
float:left;
width: 23%;
margin-right: 0;
margin-bottom: 1.25%;
}
.header {
float:left;
width: 100%;
margin-right: 1.25%;
margin-bottom: .25%;
}
label {
display: block;
text-align: center;
}
input {
width: 100%;
}
.form-style-9 ul li input[type="submit"] {
width: 10%;
}
.resume-title {
color: #af5d86;
}
.container {
margin-left: 2%;
margin-right: 2%;
}
.personal-details {
padding-bottom:1.25%;
}
.col{
float: left;
width: 23%;
margin-right: 1.25%;
margin-bottom: 1.25%;
border: 1px solid #c2c2c2;
padding: 1%;
}
You must to do this :
1) make li vertical and change content in your example to specific it vertically .
2) but id to all li and in css make the border like this
<li id='first-column'> any thing</li>
<li id='second-column'> any thing</li>
css=>
#first-column { border:1px red solid; }
#second-column { border:1px blue solid; }
I have difficulties to arrange the css bootstrap form .
On top of the picture below is the layout I get and just under is the layout I would like to obtain:
http://s27.postimg.org/dfztgn35v/flow_Root3665.png
This is: the first column witn names aligned on their last letter, and aligned input fields on the left and on the right.
Here is the css I used:
<div class="well">
<form class="form-horizontal" method="post">
<fieldset>
<legend>Event</legend>
<div class="form-group">
<label for="input-append date" class="col-lg-1 control-label">Date</label>
<div class="col-lg-3">
<div class="input-group input-append date" id="startDatePicker">
<input type="text" class="form-control" name="datepicker" id="datepicker1" readonly style="background-color: white" /><span class="input-group-addon add-on"><span class="glyphicon glyphicon-calendar"></span></span>
</div>
</div>
<div class="form-group">
<label for="input-append type" class="col-lg-1 control-label">Type</label>
<div class="col-lg-2">
<select class="form-control" id="select">
<option>select1</option>
<option>select2</option>
</select>
</div>
</div>
<div class="form-group">
<label for="inputTitle" class="col-lg-1 control-label">Title</label>
<div class="col-lg-6">
<input kl_virtual_keyboard_secure_input="on" class="form-control" id="inputTitle" placeholder="Title" type="text" maxlength="30">
</div>
</div>
<div class="form-group">
<label for="textArea" class="col-lg-1 control-label">Description</label>
<div class="col-lg-6">
<textarea class="form-control" rows="3" id="textArea" placeholder="Description" maxlength="200"></textarea>
</div>
</div>
</div>
</fieldset>
</form>
</div>
Thanks!
With some minor CSS you can acheive that. See example.
#soForm input,
#soForm select {
height: 50px;
font-size: 16px;
-webkit-border-radius: 0;
border-radius: 0;
border: 4px solid #444;
}
#soForm textarea {
font-size: 16px;
-webkit-border-radius: 0;
border-radius: 0;
border: 4px solid #444;
}
#soForm .input-group-addon {
height: 50px;
font-size: 13px;
-webkit-border-radius: 0;
border-radius: 0;
border-right: 4px solid #444;
border-top: 4px solid #444;
border-bottom: 4px solid #444;
}
.btn.btn-submit {
border-radius: 0;
height: 50px;
width: 100px;
border: 4px solid #444;
}
#media (min-width: 768px) {
#soForm .soForm {
margin: 10px auto;
}
#soForm .control-label {
margin-top: 25px;
}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<div class="well">
<div class="container">
<form id="soForm" name="soForm">
<div class="form-group">
<label for="date" class="col-sm-2 control-label">Date</label>
<div class="col-sm-5">
<div class="input-group soForm">
<input type="text" class="form-control" id="date" /> <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span>
</div>
</div>
</div>
<div class="form-group">
<label for="type" class="col-sm-2 control-label">Type</label>
<div class="col-sm-3">
<select class="form-control soForm" id="type">
<option>select1</option>
<option>select2</option>
</select>
</div>
</div>
<div class="form-group">
<label for="title" class="col-sm-2 control-label">Title</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="title" />
</div>
</div>
<div class="form-group">
<label for="description" class="col-sm-2 control-label">Description</label>
<div class="col-sm-10">
<textarea class="form-control soForm" rows="5" id="desc"></textarea>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default btn-submit">Submit</button>
</div>
</div>
</form>
</div>
</div>
I have a form where I want to put some <div> elements on the same line.
I want to have confirm password in the same line as password.
HTML
<form action="pages/php/signup.php" method="post">
<div>
<div>Name :
<div id="gtext_form">
<input type="text" name="name" />
</div>
</div>
</div>
<div class="line">
<div class="st_column">E-mail :
<div class="text_form">
<input type="text" name="email" />
</div>
</div>
<div class="nd_column">Login :
<div class="text_form">
<input type="text" name="login" />
</div>
</div>
</div>
<div class="line">
<div class="st column">Password :
<div class="text_form">
<input type="password" name="password" />
</div>
</div>
<div class="nd_column">Confirm password :
<div class="text_form">
<input type="password" name="password2" />
</div>
</div>
</div>
<div class="line">
<input type="submit" name="valider" value=" OK " />
</div>
</form>
CSS
#gtext_form input {
width: 640px;
height: 20px;
}
.text_form input {
width: 280px;
}
.st_column {
float: left;
width: 280px;
display: inline;
}
.nd_column {
float: right;
width: 280px;
display: inline;
}
.line {
padding-right:0px;
padding-left:0px;
width: 640px;
height: 60px;
}
JSFiddle
There is en error in your class name:
<div class="st column">Password :<div class="text_form"><input type="password" name="password"/></div></div>
The name should be st_column
Hi you didn't have the class for the password correct int he html. It was missing and underscore. Trying something like this:
JS Fiddle
Change your class for Password in your html to: class="st_column"
CSS
#gtext_form input {
width: 640px;
height: 20px;
}
.text_form input {
width: 280px;
}
.st_column {
float: left;
width: 280px;
display: inline;
}
.nd_column {
float: right;
width: 280px;
display: inline;
}
.line {
padding-right:0px;
padding-left:0px;
width: 640px;
height: 60px;
}
In your second <div class="line">
You have a div that reads:
<div class="st columns">
However this should be:
<div class="st_columns">
JsFiddle
The reason the confirm password wasn't on the same line as the password is because you are missing the _ in the classname: http://jsfiddle.net/7a9dL/2/
Corrected HTML:
<form action="pages/php/signup.php" method="post">
<div><div>Name :<div id="gtext_form"><input type="text" name="name"/></div></div></div>
<div class="line">
<div class="st_column">E-mail :<div class="text_form"><input type="text" name="email"/></div></div>
<div class="nd_column">Login :<div class="text_form"><input type="text" name="login"/></div></div>
</div>
<div class="line">
<div class="st_column">Password :<div class="text_form"><input type="password" name="password"/></div></div>
<div class="nd_column">Confirm password :<div class="text_form"><input type="password" name="password2"/></div></div>
</div>
<div class="line"><input type="submit" name="valider" value=" OK " /></div>
</form>
Try adding this :
.line div {
display: inline-block;
}
Tested with Firefox 27.