forms.less 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  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. // Ensure icons don't overlap text
  250. .form-control {
  251. padding-right: (@input-height-base * 1.25);
  252. }
  253. // Feedback icon (requires .glyphicon classes)
  254. .form-control-feedback {
  255. position: absolute;
  256. top: (@line-height-computed + 5); // Height of the `label` and its margin
  257. right: 0;
  258. display: block;
  259. width: @input-height-base;
  260. height: @input-height-base;
  261. line-height: @input-height-base;
  262. text-align: center;
  263. }
  264. }
  265. .has-feedback-left {
  266. position: relative;
  267. .form-control {
  268. padding-left: @input-height-base;
  269. }
  270. .form-control-feedback-left {
  271. position: absolute;
  272. top: (@line-height-computed + 5); // Height of the `label` and its margin
  273. left: 0;
  274. display: block;
  275. width: @input-height-base;
  276. height: @input-height-base;
  277. line-height: @input-height-base;
  278. text-align: center;
  279. }
  280. }
  281. // Feedback states
  282. .has-success {
  283. .form-control-validation(@brand-success);
  284. }
  285. .has-warning {
  286. .form-control-validation(@brand-warning);
  287. }
  288. .has-error {
  289. .form-control-validation(@brand-danger);
  290. }
  291. .form-control.ng-dirty.ng-invalid:not(:focus),
  292. .form-control[data-ol-dirty]:invalid:not(:focus) {
  293. border-color: @state-danger-text;
  294. .box-shadow(
  295. inset 0 1px 1px rgba(0, 0, 0, 0.075)
  296. ); // Redeclare so transitions work
  297. &:focus {
  298. border-color: darken(@state-danger-text, 10%);
  299. @shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075),
  300. 0 0 6px lighten(@state-danger-text, 20%);
  301. .box-shadow(@shadow);
  302. }
  303. }
  304. // Static form control text
  305. //
  306. // Apply class to a `p` element to make any string of text align with labels in
  307. // a horizontal form layout.
  308. .form-control-static {
  309. margin-bottom: 0; // Remove default margin from `p`
  310. }
  311. // Help text
  312. //
  313. // Apply to any element you wish to create light text for placement immediately
  314. // below a form control. Use for general help, formatting, or instructional text.
  315. .help-block {
  316. display: block; // account for any element using help-block
  317. margin-top: 5px;
  318. margin-bottom: 10px;
  319. color: lighten(@text-color, 25%); // lighten the text some for contrast
  320. }
  321. // Inline forms
  322. //
  323. // Make forms appear inline(-block) by adding the `.form-inline` class. Inline
  324. // forms begin stacked on extra small (mobile) devices and then go inline when
  325. // viewports reach <768px.
  326. //
  327. // Requires wrapping inputs and labels with `.form-group` for proper display of
  328. // default HTML form controls and our custom form controls (e.g., input groups).
  329. //
  330. // Heads up! This is mixin-ed into `.navbar-form` in navbars.less.
  331. .form-inline {
  332. // Kick in the inline
  333. @media (min-width: @screen-sm-min) {
  334. // Inline-block all the things for "inline"
  335. .form-group {
  336. display: inline-block;
  337. margin-bottom: 0;
  338. vertical-align: middle;
  339. }
  340. // In navbar-form, allow folks to *not* use `.form-group`
  341. .form-control {
  342. display: inline-block;
  343. width: auto; // Prevent labels from stacking above inputs in `.form-group`
  344. vertical-align: middle;
  345. }
  346. // Input groups need that 100% width though
  347. .input-group > .form-control {
  348. width: 100%;
  349. }
  350. .control-label {
  351. margin-bottom: 0;
  352. vertical-align: middle;
  353. }
  354. // Remove default margin on radios/checkboxes that were used for stacking, and
  355. // then undo the floating of radios and checkboxes to match (which also avoids
  356. // a bug in WebKit: https://github.com/twbs/bootstrap/issues/1969).
  357. .radio,
  358. .checkbox {
  359. display: inline-block;
  360. margin-top: 0;
  361. margin-bottom: 0;
  362. padding-left: 0;
  363. vertical-align: middle;
  364. }
  365. .radio input[type='radio'],
  366. .checkbox input[type='checkbox'] {
  367. float: none;
  368. margin-left: 0;
  369. }
  370. // Validation states
  371. //
  372. // Reposition the icon because it's now within a grid column and columns have
  373. // `position: relative;` on them. Also accounts for the grid gutter padding.
  374. .has-feedback .form-control-feedback {
  375. top: 0;
  376. }
  377. }
  378. }
  379. // Horizontal forms
  380. //
  381. // Horizontal forms are built on grid classes and allow you to create forms with
  382. // labels on the left and inputs on the right.
  383. .form-horizontal {
  384. // Consistent vertical alignment of labels, radios, and checkboxes
  385. .control-label,
  386. .radio,
  387. .checkbox,
  388. .radio-inline,
  389. .checkbox-inline {
  390. margin-top: 0;
  391. margin-bottom: 0;
  392. padding-top: (@padding-base-vertical + 1); // Default padding plus a border
  393. }
  394. // Account for padding we're adding to ensure the alignment and of help text
  395. // and other content below items
  396. .radio,
  397. .checkbox {
  398. min-height: (@line-height-computed + (@padding-base-vertical + 1));
  399. }
  400. // Make form groups behave like rows
  401. .form-group {
  402. .make-row();
  403. }
  404. .form-control-static {
  405. padding-top: (@padding-base-vertical + 1);
  406. }
  407. // Only right align form labels here when the columns stop stacking
  408. @media (min-width: @screen-sm-min) {
  409. .control-label {
  410. text-align: right;
  411. }
  412. }
  413. // Validation states
  414. //
  415. // Reposition the icon because it's now within a grid column and columns have
  416. // `position: relative;` on them. Also accounts for the grid gutter padding.
  417. .has-feedback .form-control-feedback {
  418. top: 0;
  419. right: (@grid-gutter-width / 2);
  420. }
  421. .has-feedback-left .form-control-feedback-left {
  422. top: 0;
  423. left: (@grid-gutter-width / 2);
  424. }
  425. }
  426. .invalid-feedback {
  427. display: flex;
  428. align-items: baseline;
  429. font-size: @font-size-small;
  430. .text-emphasis-variant(@state-danger-text);
  431. }