3
\$\begingroup\$

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?
\$\endgroup\$
1
\$\begingroup\$

Your code looks perfectly fine. In fact, it all validates by the validators at W3C perfectly fine, with one exception - your HTML file should be structured like this:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <title>Your Page Title Here</title>
        <!-- other code here -->
    </head>
    <body>
        <!-- your display code here -->
    </body>
</html>

The validators can be found here:

HTML validator
CSS validator

Your code seems perfectly fine the way it is, and I would say the only thing wrong with it is from the user's perspective. You have the Category menu overlapping the Title menu, which is not good; you should adjust your columns to prevent this.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ May I ask what browser you are using when you say the category menu is overlapping as I don't see that on my end \$\endgroup\$ – Jimmy Jan 23 '15 at 8:05
  • 1
    \$\begingroup\$ @Jimmy No problem. I am using IceDragon, which is based on FireFox but is more secure and has a different UI. I just tested in on IE, and it looks great there. \$\endgroup\$ – user34073 Jan 23 '15 at 16:07
  • \$\begingroup\$ IceDragon: i.imgur.com/b6l5rKv.png \$\endgroup\$ – user34073 Jan 23 '15 at 16:10
  • \$\begingroup\$ IE: i.imgur.com/6hwiZxH.png \$\endgroup\$ – user34073 Jan 23 '15 at 16:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.