forms.less 12 KB

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