forms.less 12 KB

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