I'm trying to have a HTML / CSS structure for flexible layouts for forms. I tried to look at Bootstrap codes for help with this (without actually using Bootstrap itself). I've gone with something along these lines:
http://cssdeck.com/labs/stidyuic
* {padding: 0; margin: 0; box-sizing: border-box;}
body {width: 80%; margin: 0 auto; margin-top: 30px;}
.form-row {
display: block;
}
.form-group:first-child {
padding-left: 0px;
}
.form-group {
margin-bottom: 20px;
float: left;
padding-left: 20px;
}
.col-6 {
width: 50%;
}
.col-3 {
width: 25%;
}
label {
display: block;
margin-bottom: 10px;
font-weight: bold;
}
.form-control {
display: block;
width: 100%;
height: 34px;
padding: 6px 12px;
font-size: 14px;
line-height: 1.42857;
color: #555;
vertical-align: middle;
background-color: #FFF;
background-image: none;
border: 1px solid #CCC;
border-radius: 4px;
box-shadow: 0px 1px 1px rgba(0, 0, 0, 0.075) inset;
transition: border-color 0.15s ease-in-out 0s, box-shadow 0.15s ease-in-out 0s;
}
input, button, select, textarea {
font-family: inherit;
font-size: inherit;
}
form {
display: block;
margin-top: 0em;
}
<div class="form-row">
<div class="col-6 form-group">
<label class="control-label">Title</label>
<input class="form-control" placeholder="Test" size="4" type="text">
</div>
<div class="col-3 form-group">
<label class="control-label">Category</label>
<select class="form-control">
<option value="A">
A
</option>
<option value="B">
B
</option>
</select>
</div>
<div class="col-3 form-group">
<label class="control-label">Type</label>
<select class="form-control">
<option>
A
</option>
<option>
B
</option>
<option>
C
</option>
</select>
</div>
</div>
I want to be able to do the following:
- Have anywhere from 1 to four inputs on each row.
- Have the label above the form
- Modify the form layout with CSS when the resolution changes (media query)
Questions:
- Is it a sensible approach to use this code structure in order to achieve this?
- Is taking Bootstrap’s form structure a logical approach to this problem?