aboutsummaryrefslogtreecommitdiff
path: root/less/forms.less
diff options
context:
space:
mode:
authorMark Otto <[email protected]>2013-12-15 17:15:09 -0800
committerMark Otto <[email protected]>2013-12-15 17:15:09 -0800
commit2979e4bcea25c428c801d77153dc0f663618ce20 (patch)
treebd4902fb6d5eec25641752680df172dac3cee2e6 /less/forms.less
parentd9345ff7d55e3982b36f88cb7459239a773bbfda (diff)
downloadbootstrap-2979e4bcea25c428c801d77153dc0f663618ce20.tar.xz
bootstrap-2979e4bcea25c428c801d77153dc0f663618ce20.zip
Add new form feedback states, clean up existing form styles
New stuff: * Adds `.has-feedback` and `.form-control-feedback` to show icon-based form feedback to users. Fixes #11836. * Removes the `width: 1em` on `.glyphicon` because it makes it impractical to resize the width of all icons, even if they’re not “empty” (e.g., a simple `.glyphicon { width: 30px; }` wouldn’t work, nor would a class preceeded by a parent class. Clean up: * Sets `width: auto;` on all `.form-control`s within inline forms. * Removes all the inline `select` menu `width` styles because all inputs are now `auto`. * Update form states docs to separate out sections better.
Diffstat (limited to 'less/forms.less')
-rw-r--r--less/forms.less57
1 files changed, 45 insertions, 12 deletions
diff --git a/less/forms.less b/less/forms.less
index a5f966802..530257499 100644
--- a/less/forms.less
+++ b/less/forms.less
@@ -253,15 +253,35 @@ input[type="checkbox"],
//
// Apply contextual and semantic states to individual form controls.
-// Warning
+.has-feedback {
+ // Enable absolute positioning
+ position: relative;
+
+ // Ensure icons don't overlap text
+ .form-control {
+ padding-right: (@input-height-base * 1.25);
+ }
+
+ // Feedback icon (requires .glyphicon classes)
+ .form-control-feedback {
+ position: absolute;
+ top: (@line-height-computed + 5); // Height of the `label` and it's margin
+ right: 0;
+ display: block;
+ width: @input-height-base;
+ height: @input-height-base;
+ line-height: @input-height-base;
+ text-align: center;
+ }
+}
+
+// Feedback states
.has-warning {
.form-control-validation(@state-warning-text; @state-warning-text; @state-warning-bg);
}
-// Error
.has-error {
.form-control-validation(@state-danger-text; @state-danger-text; @state-danger-bg);
}
-// Success
.has-success {
.form-control-validation(@state-success-text; @state-success-text; @state-success-bg);
}
@@ -307,7 +327,7 @@ input[type="checkbox"],
// Kick in the inline
@media (min-width: @screen-sm) {
// Inline-block all the things for "inline"
- .form-group {
+ .form-group {
display: inline-block;
margin-bottom: 0;
vertical-align: middle;
@@ -316,17 +336,13 @@ input[type="checkbox"],
// In navbar-form, allow folks to *not* use `.form-group`
.form-control {
display: inline-block;
+ width: auto; // Prevent labels from stacking above inputs in `.form-group`
vertical-align: middle;
}
- // Override `width: 100%;` when not within a `.form-group`
- select.form-control {
- width: auto;
- }
-
- // Override `width: 100%;` when not within a `.form-group`
- > select.form-control {
- width: auto;
+ .control-label {
+ margin-bottom: 0;
+ vertical-align: middle;
}
// Remove default margin on radios/checkboxes that were used for stacking, and
@@ -345,6 +361,14 @@ input[type="checkbox"],
float: none;
margin-left: 0;
}
+
+ // Validation states
+ //
+ // Reposition the icon because it's now within a grid column and columns have
+ // `position: relative;` on them. Also accounts for the grid gutter padding.
+ .has-feedback .form-control-feedback {
+ top: 0;
+ }
}
}
@@ -388,4 +412,13 @@ input[type="checkbox"],
text-align: right;
}
}
+
+ // Validation states
+ //
+ // Reposition the icon because it's now within a grid column and columns have
+ // `position: relative;` on them. Also accounts for the grid gutter padding.
+ .has-feedback .form-control-feedback {
+ top: 0;
+ right: (@grid-gutter-width / 2);
+ }
}