forms.less 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  1. //
  2. // Forms
  3. // --------------------------------------------------
  4. // Normalize non-controls
  5. //
  6. // Restyle and baseline non-control form elements.
  7. fieldset {
  8. padding: 0;
  9. margin: 0;
  10. border: 0;
  11. // Chrome and Firefox set a `min-width: -webkit-min-content;` on fieldsets,
  12. // so we reset that to ensure it behaves more like a standard block element.
  13. // See https://github.com/twbs/bootstrap/issues/12359.
  14. min-width: 0;
  15. }
  16. legend {
  17. display: block;
  18. width: 100%;
  19. padding: 0;
  20. margin-bottom: @line-height-computed;
  21. font-size: (@font-size-base * 1.5);
  22. line-height: inherit;
  23. color: @legend-color;
  24. border: 0;
  25. border-bottom: 1px solid @legend-border-color;
  26. }
  27. label {
  28. display: inline-block;
  29. margin-bottom: 5px;
  30. font-weight: bold;
  31. }
  32. // Normalize form controls
  33. //
  34. // While most of our form styles require extra classes, some basic normalization
  35. // is required to ensure optimum display with or without those classes to better
  36. // address browser inconsistencies.
  37. // Override content-box in Normalize (* isn't specific enough)
  38. input[type='search'] {
  39. .box-sizing(border-box);
  40. }
  41. // Position radios and checkboxes better
  42. input[type='radio'],
  43. input[type='checkbox'] {
  44. margin: 4px 0 0;
  45. margin-top: 1px \9; /* IE8-9 */
  46. line-height: normal;
  47. }
  48. // Set the height of file controls to match text inputs
  49. input[type='file'] {
  50. display: block;
  51. }
  52. // Make range inputs behave like textual form controls
  53. input[type='range'] {
  54. display: block;
  55. width: 100%;
  56. }
  57. // Make multiple select elements height not fixed
  58. select[multiple],
  59. select[size] {
  60. height: auto;
  61. }
  62. // Focus for file, radio, and checkbox
  63. input[type='file']:focus,
  64. input[type='radio']:focus,
  65. input[type='checkbox']:focus {
  66. .tab-focus();
  67. }
  68. // Adjust output element
  69. output {
  70. display: block;
  71. padding-top: (@padding-base-vertical + 1);
  72. font-size: @font-size-base;
  73. line-height: @line-height-base;
  74. color: @input-color;
  75. }
  76. // Common form controls
  77. //
  78. // Shared size and type resets for form controls. Apply `.form-control` to any
  79. // of the following form controls:
  80. //
  81. // select
  82. // textarea
  83. // input[type="text"]
  84. // input[type="password"]
  85. // input[type="datetime"]
  86. // input[type="datetime-local"]
  87. // input[type="date"]
  88. // input[type="month"]
  89. // input[type="time"]
  90. // input[type="week"]
  91. // input[type="number"]
  92. // input[type="email"]
  93. // input[type="url"]
  94. // input[type="search"]
  95. // input[type="tel"]
  96. // input[type="color"]
  97. .form-control when (@is-new-css = false) {
  98. display: block;
  99. width: 100%;
  100. height: @input-height-base; // Make inputs at least the height of their button counterpart (base line-height + padding + border)
  101. padding: @padding-base-vertical @padding-base-horizontal;
  102. font-size: @font-size-base;
  103. line-height: @line-height-base;
  104. color: @input-color;
  105. background-color: @input-bg;
  106. background-image: none; // Reset unusual Firefox-on-Android default style; see https://github.com/necolas/normalize.css/issues/214
  107. border: @input-border-size solid @input-border;
  108. border-radius: @input-border-radius;
  109. .box-shadow(inset 0 1px 1px rgba(0, 0, 0, 0.075));
  110. .transition(~'border-color ease-in-out .15s, box-shadow ease-in-out .15s');
  111. // Customize the `:focus` state to imitate native WebKit styles.
  112. .form-control-focus();
  113. // Placeholder
  114. .placeholder();
  115. // Disabled and read-only inputs
  116. //
  117. // HTML5 says that controls under a fieldset > legend:first-child won't be
  118. // disabled if the fieldset is disabled. Due to implementation difficulty, we
  119. // don't honor that edge case; we style them as disabled anyway.
  120. &[disabled],
  121. &[readonly],
  122. fieldset[disabled] & {
  123. cursor: not-allowed;
  124. background-color: @input-bg-disabled;
  125. opacity: 1; // iOS fix for unreadable disabled content
  126. }
  127. // Reset height for `textarea`s, and smaller border-radius
  128. textarea& {
  129. height: auto;
  130. border-radius: @border-radius-base;
  131. }
  132. // Smaller border-radius for `select` inputs
  133. select& {
  134. border-radius: @border-radius-base;
  135. }
  136. }
  137. .form-control when (@is-new-css = true) {
  138. display: block;
  139. width: 100%;
  140. height: @input-height-base; // Make inputs at least the height of their button counterpart (base line-height + padding + border)
  141. padding: @padding-base-vertical @input-padding;
  142. font-size: @font-size-base;
  143. line-height: @line-height-base;
  144. color: @input-color;
  145. background-color: @input-bg;
  146. border: @input-border-size solid @input-border;
  147. border-radius: @input-border-radius;
  148. .transition(~'border-color ease-in-out .15s, box-shadow ease-in-out .15s');
  149. // Customize the `:focus` state to imitate native WebKit styles.
  150. .form-control-focus();
  151. // Placeholder
  152. .placeholder();
  153. // Disabled and read-only inputs
  154. //
  155. // HTML5 says that controls under a fieldset > legend:first-child won't be
  156. // disabled if the fieldset is disabled. Due to implementation difficulty, we
  157. // don't honor that edge case; we style them as disabled anyway.
  158. &[disabled],
  159. &[readonly],
  160. fieldset[disabled] & {
  161. cursor: not-allowed;
  162. background-color: @input-bg-disabled;
  163. border-color: @input-bg-disabled;
  164. opacity: 1; // iOS fix for unreadable disabled content
  165. .placeholder(@neutral-40);
  166. }
  167. // Reset height for `textarea`s, and smaller border-radius
  168. textarea& {
  169. height: auto;
  170. border-radius: @border-radius-base;
  171. }
  172. // Smaller border-radius for `select` inputs
  173. select& {
  174. border-radius: @border-radius-base;
  175. }
  176. }
  177. // Search inputs in iOS
  178. //
  179. // This overrides the extra rounded corners on search inputs in iOS so that our
  180. // `.form-control` class can properly style them. Note that this cannot simply
  181. // be added to `.form-control` as it's not specific enough. For details, see
  182. // https://github.com/twbs/bootstrap/issues/11586.
  183. input[type='search'] {
  184. -webkit-appearance: none;
  185. }
  186. // Special styles for iOS date input
  187. //
  188. // In Mobile Safari, date inputs require a pixel line-height that matches the
  189. // given height of the input.
  190. input[type='date'] {
  191. line-height: @input-height-base;
  192. }
  193. // Form groups
  194. //
  195. // Designed to help with the organization and spacing of vertical forms. For
  196. // horizontal forms, use the predefined grid classes.
  197. .form-group {
  198. margin-bottom: 15px;
  199. }
  200. // Checkboxes and radios
  201. //
  202. // Indent the labels to position radios/checkboxes as hanging controls.
  203. .radio,
  204. .checkbox {
  205. display: block;
  206. min-height: @line-height-computed; // clear the floating input if there is no label text
  207. margin-top: 10px;
  208. margin-bottom: 10px;
  209. padding-left: 20px;
  210. label {
  211. display: inline;
  212. font-weight: normal;
  213. cursor: pointer;
  214. }
  215. }
  216. .fake-disabled-checkbox {
  217. opacity: 0.5;
  218. }
  219. .radio input[type='radio'],
  220. .radio-inline input[type='radio'],
  221. .checkbox input[type='checkbox'],
  222. .checkbox-inline input[type='checkbox'] {
  223. float: left;
  224. margin-left: -20px;
  225. }
  226. .radio + .radio,
  227. .checkbox + .checkbox {
  228. margin-top: -5px; // Move up sibling radios or checkboxes for tighter spacing
  229. }
  230. // Radios and checkboxes on same line
  231. .radio-inline,
  232. .checkbox-inline {
  233. display: inline-block;
  234. padding-left: 20px;
  235. margin-bottom: 0;
  236. vertical-align: middle;
  237. font-weight: normal;
  238. cursor: pointer;
  239. }
  240. .radio-inline + .radio-inline,
  241. .checkbox-inline + .checkbox-inline {
  242. margin-top: 0;
  243. margin-left: 10px; // space out consecutive inline controls
  244. }
  245. // Apply same disabled cursor tweak as for inputs
  246. //
  247. // Note: Neither radios nor checkboxes can be readonly.
  248. input[type='radio'],
  249. input[type='checkbox'],
  250. .radio,
  251. .radio-inline,
  252. .checkbox,
  253. .checkbox-inline {
  254. &[disabled],
  255. fieldset[disabled] & {
  256. cursor: not-allowed;
  257. }
  258. }
  259. // Form control sizing
  260. //
  261. // Build on `.form-control` with modifier classes to decrease or increase the
  262. // height and font-size of form controls.
  263. .input-sm {
  264. .input-size(
  265. @input-height-small; @padding-small-vertical; @padding-small-horizontal;
  266. @font-size-small; @line-height-small; @border-radius-small
  267. );
  268. }
  269. .input-lg {
  270. .input-size(
  271. @input-height-large; @padding-large-vertical; @padding-large-horizontal;
  272. @font-size-large; @line-height-large; @border-radius-large
  273. );
  274. }
  275. // Form control feedback states
  276. //
  277. // Apply contextual and semantic states to individual form controls.
  278. .has-feedback {
  279. // Enable absolute positioning
  280. position: relative;
  281. // Ensure icons don't overlap text
  282. .form-control {
  283. padding-right: (@input-height-base * 1.25);
  284. }
  285. // Feedback icon (requires .glyphicon classes)
  286. .form-control-feedback {
  287. position: absolute;
  288. top: (@line-height-computed + 5); // Height of the `label` and its margin
  289. right: 0;
  290. display: block;
  291. width: @input-height-base;
  292. height: @input-height-base;
  293. line-height: @input-height-base;
  294. text-align: center;
  295. }
  296. }
  297. .has-feedback-left {
  298. position: relative;
  299. .form-control {
  300. padding-left: @input-height-base;
  301. }
  302. .form-control-feedback-left {
  303. position: absolute;
  304. top: (@line-height-computed + 5); // Height of the `label` and its margin
  305. left: 0;
  306. display: block;
  307. width: @input-height-base;
  308. height: @input-height-base;
  309. line-height: @input-height-base;
  310. text-align: center;
  311. }
  312. }
  313. // Feedback states
  314. .has-success when(@is-new-css = false) {
  315. .form-control-validation(
  316. @state-success-text; @state-success-text; @state-success-bg
  317. );
  318. }
  319. .has-warning when(@is-new-css = false) {
  320. .form-control-validation(
  321. @state-warning-text; @state-warning-text; @state-warning-bg
  322. );
  323. }
  324. .has-error when(@is-new-css = false) {
  325. .form-control-validation(
  326. @state-danger-text; @state-danger-text; @state-danger-bg
  327. );
  328. color: @red;
  329. }
  330. .has-success when(@is-new-css = true) {
  331. .form-control-validation(@brand-success);
  332. }
  333. .has-warning when(@is-new-css = true) {
  334. .form-control-validation(@brand-warning);
  335. }
  336. .has-error when(@is-new-css = true) {
  337. .form-control-validation(@brand-danger);
  338. }
  339. .form-control.ng-dirty.ng-invalid:not(:focus),
  340. .form-control[data-ol-dirty]:invalid:not(:focus) {
  341. border-color: @state-danger-text;
  342. .box-shadow(
  343. inset 0 1px 1px rgba(0, 0, 0, 0.075)
  344. ); // Redeclare so transitions work
  345. &:focus {
  346. border-color: darken(@state-danger-text, 10%);
  347. @shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075),
  348. 0 0 6px lighten(@state-danger-text, 20%);
  349. .box-shadow(@shadow);
  350. }
  351. }
  352. // Static form control text
  353. //
  354. // Apply class to a `p` element to make any string of text align with labels in
  355. // a horizontal form layout.
  356. .form-control-static {
  357. margin-bottom: 0; // Remove default margin from `p`
  358. }
  359. // Help text
  360. //
  361. // Apply to any element you wish to create light text for placement immediately
  362. // below a form control. Use for general help, formatting, or instructional text.
  363. .help-block {
  364. display: block; // account for any element using help-block
  365. margin-top: 5px;
  366. margin-bottom: 10px;
  367. color: lighten(@text-color, 25%); // lighten the text some for contrast
  368. }
  369. // Inline forms
  370. //
  371. // Make forms appear inline(-block) by adding the `.form-inline` class. Inline
  372. // forms begin stacked on extra small (mobile) devices and then go inline when
  373. // viewports reach <768px.
  374. //
  375. // Requires wrapping inputs and labels with `.form-group` for proper display of
  376. // default HTML form controls and our custom form controls (e.g., input groups).
  377. //
  378. // Heads up! This is mixin-ed into `.navbar-form` in navbars.less.
  379. .form-inline {
  380. // Kick in the inline
  381. @media (min-width: @screen-sm-min) {
  382. // Inline-block all the things for "inline"
  383. .form-group {
  384. display: inline-block;
  385. margin-bottom: 0;
  386. vertical-align: middle;
  387. }
  388. // In navbar-form, allow folks to *not* use `.form-group`
  389. .form-control {
  390. display: inline-block;
  391. width: auto; // Prevent labels from stacking above inputs in `.form-group`
  392. vertical-align: middle;
  393. }
  394. // Input groups need that 100% width though
  395. .input-group > .form-control {
  396. width: 100%;
  397. }
  398. .control-label {
  399. margin-bottom: 0;
  400. vertical-align: middle;
  401. }
  402. // Remove default margin on radios/checkboxes that were used for stacking, and
  403. // then undo the floating of radios and checkboxes to match (which also avoids
  404. // a bug in WebKit: https://github.com/twbs/bootstrap/issues/1969).
  405. .radio,
  406. .checkbox {
  407. display: inline-block;
  408. margin-top: 0;
  409. margin-bottom: 0;
  410. padding-left: 0;
  411. vertical-align: middle;
  412. }
  413. .radio input[type='radio'],
  414. .checkbox input[type='checkbox'] {
  415. float: none;
  416. margin-left: 0;
  417. }
  418. // Validation states
  419. //
  420. // Reposition the icon because it's now within a grid column and columns have
  421. // `position: relative;` on them. Also accounts for the grid gutter padding.
  422. .has-feedback .form-control-feedback {
  423. top: 0;
  424. }
  425. }
  426. }
  427. // Horizontal forms
  428. //
  429. // Horizontal forms are built on grid classes and allow you to create forms with
  430. // labels on the left and inputs on the right.
  431. .form-horizontal {
  432. // Consistent vertical alignment of labels, radios, and checkboxes
  433. .control-label,
  434. .radio,
  435. .checkbox,
  436. .radio-inline,
  437. .checkbox-inline {
  438. margin-top: 0;
  439. margin-bottom: 0;
  440. padding-top: (@padding-base-vertical + 1); // Default padding plus a border
  441. }
  442. // Account for padding we're adding to ensure the alignment and of help text
  443. // and other content below items
  444. .radio,
  445. .checkbox {
  446. min-height: (@line-height-computed + (@padding-base-vertical + 1));
  447. }
  448. // Make form groups behave like rows
  449. .form-group {
  450. .make-row();
  451. }
  452. .form-control-static {
  453. padding-top: (@padding-base-vertical + 1);
  454. }
  455. // Only right align form labels here when the columns stop stacking
  456. @media (min-width: @screen-sm-min) {
  457. .control-label {
  458. text-align: right;
  459. }
  460. }
  461. // Validation states
  462. //
  463. // Reposition the icon because it's now within a grid column and columns have
  464. // `position: relative;` on them. Also accounts for the grid gutter padding.
  465. .has-feedback .form-control-feedback {
  466. top: 0;
  467. right: (@grid-gutter-width / 2);
  468. }
  469. .has-feedback-left .form-control-feedback-left {
  470. top: 0;
  471. left: (@grid-gutter-width / 2);
  472. }
  473. }
  474. .invalid-feedback {
  475. display: flex;
  476. align-items: baseline;
  477. font-size: @font-size-small;
  478. .text-emphasis-variant(@state-danger-text);
  479. }