説明なし

forms.less 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. // stylelint-disable selector-no-qualifying-type, property-no-vendor-prefix, media-feature-name-no-vendor-prefix
  2. //
  3. // Forms
  4. // --------------------------------------------------
  5. // Normalize non-controls
  6. //
  7. // Restyle and baseline non-control form elements.
  8. fieldset {
  9. // Chrome and Firefox set a `min-width: min-content;` on fieldsets,
  10. // so we reset that to ensure it behaves more like a standard block element.
  11. // See https://github.com/twbs/bootstrap/issues/12359.
  12. min-width: 0;
  13. padding: 0;
  14. margin: 0;
  15. border: 0;
  16. }
  17. legend {
  18. display: block;
  19. width: 100%;
  20. padding: 0;
  21. margin-bottom: @line-height-computed;
  22. font-size: (@font-size-base * 1.5);
  23. line-height: inherit;
  24. color: @legend-color;
  25. border: 0;
  26. border-bottom: 1px solid @legend-border-color;
  27. }
  28. label {
  29. display: inline-block;
  30. max-width: 100%; // Force IE8 to wrap long content (see https://github.com/twbs/bootstrap/issues/13141)
  31. margin-bottom: 5px;
  32. font-weight: 700;
  33. }
  34. // Normalize form controls
  35. //
  36. // While most of our form styles require extra classes, some basic normalization
  37. // is required to ensure optimum display with or without those classes to better
  38. // address browser inconsistencies.
  39. input[type="search"] {
  40. // Override content-box in Normalize (* isn't specific enough)
  41. .box-sizing(border-box);
  42. // Search inputs in iOS
  43. //
  44. // This overrides the extra rounded corners on search inputs in iOS so that our
  45. // `.form-control` class can properly style them. Note that this cannot simply
  46. // be added to `.form-control` as it's not specific enough. For details, see
  47. // https://github.com/twbs/bootstrap/issues/11586.
  48. -webkit-appearance: none;
  49. appearance: none;
  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. // Apply same disabled cursor tweak as for inputs
  58. // Some special care is needed because <label>s don't inherit their parent's `cursor`.
  59. //
  60. // Note: Neither radios nor checkboxes can be readonly.
  61. &[disabled],
  62. &.disabled,
  63. fieldset[disabled] & {
  64. cursor: @cursor-disabled;
  65. }
  66. }
  67. input[type="file"] {
  68. display: block;
  69. }
  70. // Make range inputs behave like textual form controls
  71. input[type="range"] {
  72. display: block;
  73. width: 100%;
  74. }
  75. // Make multiple select elements height not fixed
  76. select[multiple],
  77. select[size] {
  78. height: auto;
  79. }
  80. // Focus for file, radio, and checkbox
  81. input[type="file"]:focus,
  82. input[type="radio"]:focus,
  83. input[type="checkbox"]:focus {
  84. .tab-focus();
  85. }
  86. // Adjust output element
  87. output {
  88. display: block;
  89. padding-top: (@padding-base-vertical + 1);
  90. font-size: @font-size-base;
  91. line-height: @line-height-base;
  92. color: @input-color;
  93. }
  94. // Common form controls
  95. //
  96. // Shared size and type resets for form controls. Apply `.form-control` to any
  97. // of the following form controls:
  98. //
  99. // select
  100. // textarea
  101. // input[type="text"]
  102. // input[type="password"]
  103. // input[type="datetime"]
  104. // input[type="datetime-local"]
  105. // input[type="date"]
  106. // input[type="month"]
  107. // input[type="time"]
  108. // input[type="week"]
  109. // input[type="number"]
  110. // input[type="email"]
  111. // input[type="url"]
  112. // input[type="search"]
  113. // input[type="tel"]
  114. // input[type="color"]
  115. .form-control {
  116. display: block;
  117. width: 100%;
  118. height: @input-height-base; // Make inputs at least the height of their button counterpart (base line-height + padding + border)
  119. padding: @padding-base-vertical @padding-base-horizontal;
  120. font-size: @font-size-base;
  121. line-height: @line-height-base;
  122. color: @input-color;
  123. background-color: @input-bg;
  124. background-image: none; // Reset unusual Firefox-on-Android default style; see https://github.com/necolas/normalize.css/issues/214
  125. border: 1px solid @input-border;
  126. border-radius: @input-border-radius; // Note: This has no effect on <select>s in some browsers, due to the limited stylability of <select>s in CSS.
  127. .box-shadow(inset 0 1px 1px rgba(0, 0, 0, .075));
  128. .transition(~"border-color ease-in-out .15s, box-shadow ease-in-out .15s");
  129. // Customize the `:focus` state to imitate native WebKit styles.
  130. .form-control-focus();
  131. // Placeholder
  132. .placeholder();
  133. // Unstyle the caret on `<select>`s in IE10+.
  134. &::-ms-expand {
  135. background-color: transparent;
  136. border: 0;
  137. }
  138. // Disabled and read-only inputs
  139. //
  140. // HTML5 says that controls under a fieldset > legend:first-child won't be
  141. // disabled if the fieldset is disabled. Due to implementation difficulty, we
  142. // don't honor that edge case; we style them as disabled anyway.
  143. &[disabled],
  144. &[readonly],
  145. fieldset[disabled] & {
  146. background-color: @input-bg-disabled;
  147. opacity: 1; // iOS fix for unreadable disabled content; see https://github.com/twbs/bootstrap/issues/11655
  148. }
  149. &[disabled],
  150. fieldset[disabled] & {
  151. cursor: @cursor-disabled;
  152. }
  153. // Reset height for `textarea`s
  154. textarea& {
  155. height: auto;
  156. }
  157. }
  158. // Special styles for iOS temporal inputs
  159. //
  160. // In Mobile Safari, setting `display: block` on temporal inputs causes the
  161. // text within the input to become vertically misaligned. As a workaround, we
  162. // set a pixel line-height that matches the given height of the input, but only
  163. // for Safari. See https://bugs.webkit.org/show_bug.cgi?id=139848
  164. //
  165. // Note that as of 9.3, iOS doesn't support `week`.
  166. @media screen and (-webkit-min-device-pixel-ratio: 0) {
  167. input[type="date"],
  168. input[type="time"],
  169. input[type="datetime-local"],
  170. input[type="month"] {
  171. &.form-control {
  172. line-height: @input-height-base;
  173. }
  174. &.input-sm,
  175. .input-group-sm & {
  176. line-height: @input-height-small;
  177. }
  178. &.input-lg,
  179. .input-group-lg & {
  180. line-height: @input-height-large;
  181. }
  182. }
  183. }
  184. // Form groups
  185. //
  186. // Designed to help with the organization and spacing of vertical forms. For
  187. // horizontal forms, use the predefined grid classes.
  188. .form-group {
  189. margin-bottom: @form-group-margin-bottom;
  190. }
  191. // Checkboxes and radios
  192. //
  193. // Indent the labels to position radios/checkboxes as hanging controls.
  194. .radio,
  195. .checkbox {
  196. position: relative;
  197. display: block;
  198. margin-top: 10px;
  199. margin-bottom: 10px;
  200. // These are used on elements with <label> descendants
  201. &.disabled,
  202. fieldset[disabled] & {
  203. label {
  204. cursor: @cursor-disabled;
  205. }
  206. }
  207. label {
  208. min-height: @line-height-computed; // Ensure the input doesn't jump when there is no text
  209. padding-left: 20px;
  210. margin-bottom: 0;
  211. font-weight: 400;
  212. cursor: pointer;
  213. }
  214. }
  215. .radio input[type="radio"],
  216. .radio-inline input[type="radio"],
  217. .checkbox input[type="checkbox"],
  218. .checkbox-inline input[type="checkbox"] {
  219. position: absolute;
  220. margin-top: 4px \9;
  221. margin-left: -20px;
  222. }
  223. .radio + .radio,
  224. .checkbox + .checkbox {
  225. margin-top: -5px; // Move up sibling radios or checkboxes for tighter spacing
  226. }
  227. // Radios and checkboxes on same line
  228. .radio-inline,
  229. .checkbox-inline {
  230. position: relative;
  231. display: inline-block;
  232. padding-left: 20px;
  233. margin-bottom: 0;
  234. font-weight: 400;
  235. vertical-align: middle;
  236. cursor: pointer;
  237. // These are used directly on <label>s
  238. &.disabled,
  239. fieldset[disabled] & {
  240. cursor: @cursor-disabled;
  241. }
  242. }
  243. .radio-inline + .radio-inline,
  244. .checkbox-inline + .checkbox-inline {
  245. margin-top: 0;
  246. margin-left: 10px; // space out consecutive inline controls
  247. }
  248. // Static form control text
  249. //
  250. // Apply class to a `p` element to make any string of text align with labels in
  251. // a horizontal form layout.
  252. .form-control-static {
  253. min-height: (@line-height-computed + @font-size-base);
  254. // Size it appropriately next to real form controls
  255. padding-top: (@padding-base-vertical + 1);
  256. padding-bottom: (@padding-base-vertical + 1);
  257. // Remove default margin from `p`
  258. margin-bottom: 0;
  259. &.input-lg,
  260. &.input-sm {
  261. padding-right: 0;
  262. padding-left: 0;
  263. }
  264. }
  265. // Form control sizing
  266. //
  267. // Build on `.form-control` with modifier classes to decrease or increase the
  268. // height and font-size of form controls.
  269. //
  270. // The `.form-group-* form-control` variations are sadly duplicated to avoid the
  271. // issue documented in https://github.com/twbs/bootstrap/issues/15074.
  272. .input-sm {
  273. .input-size(@input-height-small; @padding-small-vertical; @padding-small-horizontal; @font-size-small; @line-height-small; @input-border-radius-small);
  274. }
  275. .form-group-sm {
  276. .form-control {
  277. height: @input-height-small;
  278. padding: @padding-small-vertical @padding-small-horizontal;
  279. font-size: @font-size-small;
  280. line-height: @line-height-small;
  281. border-radius: @input-border-radius-small;
  282. }
  283. select.form-control {
  284. height: @input-height-small;
  285. line-height: @input-height-small;
  286. }
  287. textarea.form-control,
  288. select[multiple].form-control {
  289. height: auto;
  290. }
  291. .form-control-static {
  292. height: @input-height-small;
  293. min-height: (@line-height-computed + @font-size-small);
  294. padding: (@padding-small-vertical + 1) @padding-small-horizontal;
  295. font-size: @font-size-small;
  296. line-height: @line-height-small;
  297. }
  298. }
  299. .input-lg {
  300. .input-size(@input-height-large; @padding-large-vertical; @padding-large-horizontal; @font-size-large; @line-height-large; @input-border-radius-large);
  301. }
  302. .form-group-lg {
  303. .form-control {
  304. height: @input-height-large;
  305. padding: @padding-large-vertical @padding-large-horizontal;
  306. font-size: @font-size-large;
  307. line-height: @line-height-large;
  308. border-radius: @input-border-radius-large;
  309. }
  310. select.form-control {
  311. height: @input-height-large;
  312. line-height: @input-height-large;
  313. }
  314. textarea.form-control,
  315. select[multiple].form-control {
  316. height: auto;
  317. }
  318. .form-control-static {
  319. height: @input-height-large;
  320. min-height: (@line-height-computed + @font-size-large);
  321. padding: (@padding-large-vertical + 1) @padding-large-horizontal;
  322. font-size: @font-size-large;
  323. line-height: @line-height-large;
  324. }
  325. }
  326. // Form control feedback states
  327. //
  328. // Apply contextual and semantic states to individual form controls.
  329. .has-feedback {
  330. // Enable absolute positioning
  331. position: relative;
  332. // Ensure icons don't overlap text
  333. .form-control {
  334. padding-right: (@input-height-base * 1.25);
  335. }
  336. }
  337. // Feedback icon (requires .glyphicon classes)
  338. .form-control-feedback {
  339. position: absolute;
  340. top: 0;
  341. right: 0;
  342. z-index: 2; // Ensure icon is above input groups
  343. display: block;
  344. width: @input-height-base;
  345. height: @input-height-base;
  346. line-height: @input-height-base;
  347. text-align: center;
  348. pointer-events: none;
  349. }
  350. .input-lg + .form-control-feedback,
  351. .input-group-lg + .form-control-feedback,
  352. .form-group-lg .form-control + .form-control-feedback {
  353. width: @input-height-large;
  354. height: @input-height-large;
  355. line-height: @input-height-large;
  356. }
  357. .input-sm + .form-control-feedback,
  358. .input-group-sm + .form-control-feedback,
  359. .form-group-sm .form-control + .form-control-feedback {
  360. width: @input-height-small;
  361. height: @input-height-small;
  362. line-height: @input-height-small;
  363. }
  364. // Feedback states
  365. .has-success {
  366. .form-control-validation(@state-success-text; @state-success-text; @state-success-bg);
  367. }
  368. .has-warning {
  369. .form-control-validation(@state-warning-text; @state-warning-text; @state-warning-bg);
  370. }
  371. .has-error {
  372. .form-control-validation(@state-danger-text; @state-danger-text; @state-danger-bg);
  373. }
  374. // Reposition feedback icon if input has visible label above
  375. .has-feedback label {
  376. & ~ .form-control-feedback {
  377. top: (@line-height-computed + 5); // Height of the `label` and its margin
  378. }
  379. &.sr-only ~ .form-control-feedback {
  380. top: 0;
  381. }
  382. }
  383. // Help text
  384. //
  385. // Apply to any element you wish to create light text for placement immediately
  386. // below a form control. Use for general help, formatting, or instructional text.
  387. .help-block {
  388. display: block; // account for any element using help-block
  389. margin-top: 5px;
  390. margin-bottom: 10px;
  391. color: lighten(@text-color, 25%); // lighten the text some for contrast
  392. }
  393. // Inline forms
  394. //
  395. // Make forms appear inline(-block) by adding the `.form-inline` class. Inline
  396. // forms begin stacked on extra small (mobile) devices and then go inline when
  397. // viewports reach <768px.
  398. //
  399. // Requires wrapping inputs and labels with `.form-group` for proper display of
  400. // default HTML form controls and our custom form controls (e.g., input groups).
  401. //
  402. // Heads up! This is mixin-ed into `.navbar-form` in navbars.less.
  403. .form-inline {
  404. // Kick in the inline
  405. @media (min-width: @screen-sm-min) {
  406. // Inline-block all the things for "inline"
  407. .form-group {
  408. display: inline-block;
  409. margin-bottom: 0;
  410. vertical-align: middle;
  411. }
  412. // In navbar-form, allow folks to *not* use `.form-group`
  413. .form-control {
  414. display: inline-block;
  415. width: auto; // Prevent labels from stacking above inputs in `.form-group`
  416. vertical-align: middle;
  417. }
  418. // Make static controls behave like regular ones
  419. .form-control-static {
  420. display: inline-block;
  421. }
  422. .input-group {
  423. display: inline-table;
  424. vertical-align: middle;
  425. .input-group-addon,
  426. .input-group-btn,
  427. .form-control {
  428. width: auto;
  429. }
  430. }
  431. // Input groups need that 100% width though
  432. .input-group > .form-control {
  433. width: 100%;
  434. }
  435. .control-label {
  436. margin-bottom: 0;
  437. vertical-align: middle;
  438. }
  439. // Remove default margin on radios/checkboxes that were used for stacking, and
  440. // then undo the floating of radios and checkboxes to match.
  441. .radio,
  442. .checkbox {
  443. display: inline-block;
  444. margin-top: 0;
  445. margin-bottom: 0;
  446. vertical-align: middle;
  447. label {
  448. padding-left: 0;
  449. }
  450. }
  451. .radio input[type="radio"],
  452. .checkbox input[type="checkbox"] {
  453. position: relative;
  454. margin-left: 0;
  455. }
  456. // Re-override the feedback icon.
  457. .has-feedback .form-control-feedback {
  458. top: 0;
  459. }
  460. }
  461. }
  462. // Horizontal forms
  463. //
  464. // Horizontal forms are built on grid classes and allow you to create forms with
  465. // labels on the left and inputs on the right.
  466. .form-horizontal {
  467. // Consistent vertical alignment of radios and checkboxes
  468. //
  469. // Labels also get some reset styles, but that is scoped to a media query below.
  470. .radio,
  471. .checkbox,
  472. .radio-inline,
  473. .checkbox-inline {
  474. padding-top: (@padding-base-vertical + 1); // Default padding plus a border
  475. margin-top: 0;
  476. margin-bottom: 0;
  477. }
  478. // Account for padding we're adding to ensure the alignment and of help text
  479. // and other content below items
  480. .radio,
  481. .checkbox {
  482. min-height: (@line-height-computed + (@padding-base-vertical + 1));
  483. }
  484. // Make form groups behave like rows
  485. .form-group {
  486. .make-row();
  487. }
  488. // Reset spacing and right align labels, but scope to media queries so that
  489. // labels on narrow viewports stack the same as a default form example.
  490. @media (min-width: @screen-sm-min) {
  491. .control-label {
  492. padding-top: (@padding-base-vertical + 1); // Default padding plus a border
  493. margin-bottom: 0;
  494. text-align: right;
  495. }
  496. }
  497. // Validation states
  498. //
  499. // Reposition the icon because it's now within a grid column and columns have
  500. // `position: relative;` on them. Also accounts for the grid gutter padding.
  501. .has-feedback .form-control-feedback {
  502. right: floor((@grid-gutter-width / 2));
  503. }
  504. // Form group sizes
  505. //
  506. // Quick utility class for applying `.input-lg` and `.input-sm` styles to the
  507. // inputs and labels within a `.form-group`.
  508. .form-group-lg {
  509. @media (min-width: @screen-sm-min) {
  510. .control-label {
  511. padding-top: (@padding-large-vertical + 1);
  512. font-size: @font-size-large;
  513. }
  514. }
  515. }
  516. .form-group-sm {
  517. @media (min-width: @screen-sm-min) {
  518. .control-label {
  519. padding-top: (@padding-small-vertical + 1);
  520. font-size: @font-size-small;
  521. }
  522. }
  523. }
  524. }