forms.less 14 KB

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