forms.less 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  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 {
  106. display: block;
  107. width: 100%;
  108. height: @input-height-base;
  109. padding: @padding-base-vertical @input-padding;
  110. font-size: @font-size-base;
  111. line-height: @line-height-base;
  112. color: @input-color;
  113. background-color: @input-bg;
  114. border: @input-border-size solid @input-border;
  115. border-radius: @input-border-radius;
  116. .transition(~'border-color ease-in-out .15s, box-shadow ease-in-out .15s');
  117. // Customize the `:focus` state to imitate native WebKit styles.
  118. .form-control-focus();
  119. // Placeholder
  120. .placeholder();
  121. // Disabled and read-only inputs
  122. //
  123. // HTML5 says that controls under a fieldset > legend:first-child won't be
  124. // disabled if the fieldset is disabled. Due to implementation difficulty, we
  125. // don't honor that edge case; we style them as disabled anyway.
  126. &[disabled],
  127. &[readonly],
  128. fieldset[disabled] & {
  129. cursor: not-allowed;
  130. background-color: @input-bg-disabled;
  131. border-color: @input-bg-disabled;
  132. opacity: 1; // iOS fix for unreadable disabled content
  133. .placeholder(@neutral-40);
  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. // Search inputs in iOS
  146. //
  147. // This overrides the extra rounded corners on search inputs in iOS so that our
  148. // `.form-control` class can properly style them. Note that this cannot simply
  149. // be added to `.form-control` as it's not specific enough. For details, see
  150. // https://github.com/twbs/bootstrap/issues/11586.
  151. input[type='search'] {
  152. -webkit-appearance: none;
  153. }
  154. // Special styles for iOS date input
  155. //
  156. // In Mobile Safari, date inputs require a pixel line-height that matches the
  157. // given height of the input.
  158. input[type='date'] {
  159. line-height: @input-height-base;
  160. }
  161. // Form groups
  162. //
  163. // Designed to help with the organization and spacing of vertical forms. For
  164. // horizontal forms, use the predefined grid classes.
  165. .form-group {
  166. margin-bottom: 15px;
  167. }
  168. // Checkboxes and radios
  169. //
  170. // Indent the labels to position radios/checkboxes as hanging controls.
  171. .radio,
  172. .checkbox {
  173. display: block;
  174. min-height: @line-height-computed; // clear the floating input if there is no label text
  175. margin-top: 10px;
  176. margin-bottom: 10px;
  177. padding-left: 20px;
  178. label {
  179. display: inline;
  180. font-weight: normal;
  181. cursor: pointer;
  182. }
  183. }
  184. .fake-disabled-checkbox {
  185. opacity: 0.5;
  186. }
  187. .radio input[type='radio'],
  188. .radio-inline input[type='radio'],
  189. .checkbox input[type='checkbox'],
  190. .checkbox-inline input[type='checkbox'] {
  191. float: left;
  192. margin-left: -20px;
  193. }
  194. .radio + .radio,
  195. .checkbox + .checkbox {
  196. margin-top: -5px; // Move up sibling radios or checkboxes for tighter spacing
  197. }
  198. // Radios and checkboxes on same line
  199. .radio-inline,
  200. .checkbox-inline {
  201. display: inline-block;
  202. padding-left: 20px;
  203. margin-bottom: 0;
  204. vertical-align: middle;
  205. font-weight: normal;
  206. cursor: pointer;
  207. }
  208. .radio-inline + .radio-inline,
  209. .checkbox-inline + .checkbox-inline {
  210. margin-top: 0;
  211. margin-left: 10px; // space out consecutive inline controls
  212. }
  213. // Apply same disabled cursor tweak as for inputs
  214. //
  215. // Note: Neither radios nor checkboxes can be readonly.
  216. input[type='radio'],
  217. input[type='checkbox'],
  218. .radio,
  219. .radio-inline,
  220. .checkbox,
  221. .checkbox-inline {
  222. &[disabled],
  223. fieldset[disabled] & {
  224. cursor: not-allowed;
  225. }
  226. }
  227. // Form control sizing
  228. //
  229. // Build on `.form-control` with modifier classes to decrease or increase the
  230. // height and font-size of form controls.
  231. .input-sm {
  232. .input-size(
  233. @input-height-small; @padding-small-vertical; @padding-small-horizontal;
  234. @font-size-small; @line-height-small; @border-radius-small
  235. );
  236. }
  237. .input-lg {
  238. .input-size(
  239. @input-height-large; @padding-large-vertical; @padding-large-horizontal;
  240. @font-size-large; @line-height-large; @border-radius-large
  241. );
  242. }
  243. // Form control feedback states
  244. //
  245. // Apply contextual and semantic states to individual form controls.
  246. .has-feedback {
  247. // Enable absolute positioning
  248. position: relative;
  249. // Feedback icon (requires .glyphicon classes)
  250. .form-control-feedback {
  251. position: absolute;
  252. top: (@line-height-computed + 5); // Height of the `label` and its margin
  253. right: 0;
  254. display: block;
  255. width: @input-height-base;
  256. height: @input-height-base;
  257. line-height: @input-height-base;
  258. text-align: center;
  259. }
  260. }
  261. .has-feedback-left {
  262. position: relative;
  263. .form-control {
  264. padding-left: @input-height-base;
  265. }
  266. .form-control-feedback-left {
  267. position: absolute;
  268. top: (@line-height-computed + 5); // Height of the `label` and its margin
  269. left: 0;
  270. display: block;
  271. width: @input-height-base;
  272. height: @input-height-base;
  273. line-height: @input-height-base;
  274. text-align: center;
  275. }
  276. }
  277. // Feedback states
  278. .has-success {
  279. .form-control-validation(@brand-success);
  280. }
  281. .has-warning {
  282. .form-control-validation(@brand-warning);
  283. }
  284. .has-error {
  285. .form-control-validation(@brand-danger);
  286. }
  287. .form-control.ng-dirty.ng-invalid:not(:focus),
  288. .form-control[data-ol-dirty]:invalid:not(:focus) {
  289. border-color: @state-danger-text;
  290. .box-shadow(
  291. inset 0 1px 1px rgba(0, 0, 0, 0.075)
  292. ); // Redeclare so transitions work
  293. &:focus {
  294. border-color: darken(@state-danger-text, 10%);
  295. @shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075),
  296. 0 0 6px lighten(@state-danger-text, 20%);
  297. .box-shadow(@shadow);
  298. }
  299. }
  300. // Static form control text
  301. //
  302. // Apply class to a `p` element to make any string of text align with labels in
  303. // a horizontal form layout.
  304. .form-control-static {
  305. margin-bottom: 0; // Remove default margin from `p`
  306. }
  307. // Help text
  308. //
  309. // Apply to any element you wish to create light text for placement immediately
  310. // below a form control. Use for general help, formatting, or instructional text.
  311. .help-block {
  312. display: block; // account for any element using help-block
  313. margin-top: 5px;
  314. margin-bottom: 10px;
  315. color: lighten(@text-color, 25%); // lighten the text some for contrast
  316. }
  317. // Inline forms
  318. //
  319. // Make forms appear inline(-block) by adding the `.form-inline` class. Inline
  320. // forms begin stacked on extra small (mobile) devices and then go inline when
  321. // viewports reach <768px.
  322. //
  323. // Requires wrapping inputs and labels with `.form-group` for proper display of
  324. // default HTML form controls and our custom form controls (e.g., input groups).
  325. //
  326. // Heads up! This is mixin-ed into `.navbar-form` in navbars.less.
  327. .form-inline {
  328. // Kick in the inline
  329. @media (min-width: @screen-sm-min) {
  330. // Inline-block all the things for "inline"
  331. .form-group {
  332. display: inline-block;
  333. margin-bottom: 0;
  334. vertical-align: middle;
  335. }
  336. // In navbar-form, allow folks to *not* use `.form-group`
  337. .form-control {
  338. display: inline-block;
  339. width: auto; // Prevent labels from stacking above inputs in `.form-group`
  340. vertical-align: middle;
  341. }
  342. // Input groups need that 100% width though
  343. .input-group > .form-control {
  344. width: 100%;
  345. }
  346. .control-label {
  347. margin-bottom: 0;
  348. vertical-align: middle;
  349. }
  350. // Remove default margin on radios/checkboxes that were used for stacking, and
  351. // then undo the floating of radios and checkboxes to match (which also avoids
  352. // a bug in WebKit: https://github.com/twbs/bootstrap/issues/1969).
  353. .radio,
  354. .checkbox {
  355. display: inline-block;
  356. margin-top: 0;
  357. margin-bottom: 0;
  358. padding-left: 0;
  359. vertical-align: middle;
  360. }
  361. .radio input[type='radio'],
  362. .checkbox input[type='checkbox'] {
  363. float: none;
  364. margin-left: 0;
  365. }
  366. // Validation states
  367. //
  368. // Reposition the icon because it's now within a grid column and columns have
  369. // `position: relative;` on them. Also accounts for the grid gutter padding.
  370. .has-feedback .form-control-feedback {
  371. top: 0;
  372. }
  373. }
  374. }
  375. // Horizontal forms
  376. //
  377. // Horizontal forms are built on grid classes and allow you to create forms with
  378. // labels on the left and inputs on the right.
  379. .form-horizontal {
  380. // Consistent vertical alignment of labels, radios, and checkboxes
  381. .control-label,
  382. .radio,
  383. .checkbox,
  384. .radio-inline,
  385. .checkbox-inline {
  386. margin-top: 0;
  387. margin-bottom: 0;
  388. padding-top: (@padding-base-vertical + 1); // Default padding plus a border
  389. }
  390. // Account for padding we're adding to ensure the alignment and of help text
  391. // and other content below items
  392. .radio,
  393. .checkbox {
  394. min-height: (@line-height-computed + (@padding-base-vertical + 1));
  395. }
  396. // Make form groups behave like rows
  397. .form-group {
  398. .make-row();
  399. }
  400. .form-control-static {
  401. padding-top: (@padding-base-vertical + 1);
  402. }
  403. // Only right align form labels here when the columns stop stacking
  404. @media (min-width: @screen-sm-min) {
  405. .control-label {
  406. text-align: right;
  407. }
  408. }
  409. // Validation states
  410. //
  411. // Reposition the icon because it's now within a grid column and columns have
  412. // `position: relative;` on them. Also accounts for the grid gutter padding.
  413. .has-feedback .form-control-feedback {
  414. top: 0;
  415. right: (@grid-gutter-width / 2);
  416. }
  417. .has-feedback-left .form-control-feedback-left {
  418. top: 0;
  419. left: (@grid-gutter-width / 2);
  420. }
  421. }
  422. .invalid-feedback {
  423. display: flex;
  424. align-items: baseline;
  425. font-size: @font-size-small;
  426. .text-emphasis-variant(@state-danger-text);
  427. }