forms.less 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  1. //
  2. // Forms
  3. // --------------------------------------------------
  4. // GENERAL STYLES
  5. // --------------
  6. // Make all forms have space below them
  7. form {
  8. margin: 0 0 @baseLineHeight;
  9. }
  10. fieldset {
  11. padding: 0;
  12. margin: 0;
  13. border: 0;
  14. }
  15. // Groups of fields with labels on top (legends)
  16. legend {
  17. display: block;
  18. width: 100%;
  19. padding: 0;
  20. margin-bottom: @baseLineHeight;
  21. font-size: @baseFontSize * 1.5;
  22. line-height: @baseLineHeight * 2;
  23. color: @grayDark;
  24. border: 0;
  25. border-bottom: 1px solid #e5e5e5;
  26. // Small
  27. small {
  28. font-size: @baseLineHeight * .75;
  29. color: @grayLight;
  30. }
  31. }
  32. // Set font for forms
  33. label,
  34. input,
  35. button,
  36. select,
  37. textarea {
  38. #font > .shorthand(@baseFontSize,normal,@baseLineHeight); // Set size, weight, line-height here
  39. }
  40. input,
  41. button,
  42. select,
  43. textarea {
  44. font-family: @baseFontFamily; // And only set font-family here for those that need it (note the missing label element)
  45. }
  46. // Identify controls by their labels
  47. label {
  48. display: block;
  49. margin-bottom: 5px;
  50. }
  51. // Form controls
  52. // -------------------------
  53. // Shared size and type resets
  54. select,
  55. textarea,
  56. input[type="text"],
  57. input[type="password"],
  58. input[type="datetime"],
  59. input[type="datetime-local"],
  60. input[type="date"],
  61. input[type="month"],
  62. input[type="time"],
  63. input[type="week"],
  64. input[type="number"],
  65. input[type="email"],
  66. input[type="url"],
  67. input[type="search"],
  68. input[type="tel"],
  69. input[type="color"],
  70. .uneditable-input {
  71. display: inline-block;
  72. height: @baseLineHeight;
  73. padding: 4px 6px;
  74. margin-bottom: @baseLineHeight / 2;
  75. font-size: @baseFontSize;
  76. line-height: @baseLineHeight;
  77. color: @gray;
  78. .border-radius(@inputBorderRadius);
  79. vertical-align: middle;
  80. }
  81. // Reset appearance properties for textual inputs and textarea
  82. // Declare width for legacy (can't be on input[type=*] selectors or it's too specific)
  83. input,
  84. textarea,
  85. .uneditable-input {
  86. width: 206px; // plus 12px padding and 2px border
  87. }
  88. // Reset height since textareas have rows
  89. textarea {
  90. height: auto;
  91. }
  92. // Everything else
  93. textarea,
  94. input[type="text"],
  95. input[type="password"],
  96. input[type="datetime"],
  97. input[type="datetime-local"],
  98. input[type="date"],
  99. input[type="month"],
  100. input[type="time"],
  101. input[type="week"],
  102. input[type="number"],
  103. input[type="email"],
  104. input[type="url"],
  105. input[type="search"],
  106. input[type="tel"],
  107. input[type="color"],
  108. .uneditable-input {
  109. background-color: @inputBackground;
  110. border: 1px solid @inputBorder;
  111. .box-shadow(inset 0 1px 1px rgba(0,0,0,.075));
  112. .transition(~"border linear .2s, box-shadow linear .2s");
  113. // Focus state
  114. &:focus {
  115. border-color: rgba(82,168,236,.8);
  116. outline: 0;
  117. outline: thin dotted \9; /* IE6-9 */
  118. .box-shadow(~"inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(82,168,236,.6)");
  119. }
  120. }
  121. // Position radios and checkboxes better
  122. input[type="radio"],
  123. input[type="checkbox"] {
  124. margin: 4px 0 0;
  125. *margin-top: 0; /* IE7 */
  126. margin-top: 1px \9; /* IE8-9 */
  127. line-height: normal;
  128. }
  129. // Reset width of input images, buttons, radios, checkboxes
  130. input[type="file"],
  131. input[type="image"],
  132. input[type="submit"],
  133. input[type="reset"],
  134. input[type="button"],
  135. input[type="radio"],
  136. input[type="checkbox"] {
  137. width: auto; // Override of generic input selector
  138. }
  139. // Set the height of select and file controls to match text inputs
  140. select,
  141. input[type="file"] {
  142. height: @inputHeight; /* In IE7, the height of the select element cannot be changed by height, only font-size */
  143. *margin-top: 4px; /* For IE7, add top margin to align select with labels */
  144. line-height: @inputHeight;
  145. }
  146. // Make select elements obey height by applying a border
  147. select {
  148. width: 220px; // default input width + 10px of padding that doesn't get applied
  149. border: 1px solid @inputBorder;
  150. background-color: @inputBackground; // Chrome on Linux and Mobile Safari need background-color
  151. }
  152. // Make multiple select elements height not fixed
  153. select[multiple],
  154. select[size] {
  155. height: auto;
  156. }
  157. // Focus for select, file, radio, and checkbox
  158. select:focus,
  159. input[type="file"]:focus,
  160. input[type="radio"]:focus,
  161. input[type="checkbox"]:focus {
  162. .tab-focus();
  163. }
  164. // Uneditable inputs
  165. // -------------------------
  166. // Make uneditable inputs look inactive
  167. .uneditable-input,
  168. .uneditable-textarea {
  169. color: @grayLight;
  170. background-color: darken(@inputBackground, 1%);
  171. border-color: @inputBorder;
  172. .box-shadow(inset 0 1px 2px rgba(0,0,0,.025));
  173. cursor: not-allowed;
  174. }
  175. // For text that needs to appear as an input but should not be an input
  176. .uneditable-input {
  177. overflow: hidden; // prevent text from wrapping, but still cut it off like an input does
  178. white-space: nowrap;
  179. }
  180. // Make uneditable textareas behave like a textarea
  181. .uneditable-textarea {
  182. width: auto;
  183. height: auto;
  184. }
  185. // Placeholder
  186. // -------------------------
  187. // Placeholder text gets special styles because when browsers invalidate entire lines if it doesn't understand a selector
  188. input,
  189. textarea {
  190. .placeholder();
  191. }
  192. // CHECKBOXES & RADIOS
  193. // -------------------
  194. // Indent the labels to position radios/checkboxes as hanging
  195. .radio,
  196. .checkbox {
  197. min-height: @baseLineHeight; // clear the floating input if there is no label text
  198. padding-left: 20px;
  199. }
  200. .radio input[type="radio"],
  201. .checkbox input[type="checkbox"] {
  202. float: left;
  203. margin-left: -20px;
  204. }
  205. // Move the options list down to align with labels
  206. .controls > .radio:first-child,
  207. .controls > .checkbox:first-child {
  208. padding-top: 5px; // has to be padding because margin collaspes
  209. }
  210. // Radios and checkboxes on same line
  211. // TODO v3: Convert .inline to .control-inline
  212. .radio.inline,
  213. .checkbox.inline {
  214. display: inline-block;
  215. padding-top: 5px;
  216. margin-bottom: 0;
  217. vertical-align: middle;
  218. }
  219. .radio.inline + .radio.inline,
  220. .checkbox.inline + .checkbox.inline {
  221. margin-left: 10px; // space out consecutive inline controls
  222. }
  223. // INPUT SIZES
  224. // -----------
  225. // General classes for quick sizes
  226. .input-mini { width: 60px; }
  227. .input-small { width: 90px; }
  228. .input-medium { width: 150px; }
  229. .input-large { width: 210px; }
  230. .input-xlarge { width: 270px; }
  231. .input-xxlarge { width: 530px; }
  232. // Grid style input sizes
  233. input[class*="span"],
  234. select[class*="span"],
  235. textarea[class*="span"],
  236. .uneditable-input[class*="span"],
  237. // Redeclare since the fluid row class is more specific
  238. .row-fluid input[class*="span"],
  239. .row-fluid select[class*="span"],
  240. .row-fluid textarea[class*="span"],
  241. .row-fluid .uneditable-input[class*="span"] {
  242. float: none;
  243. margin-left: 0;
  244. }
  245. // Ensure input-prepend/append never wraps
  246. .input-append input[class*="span"],
  247. .input-append .uneditable-input[class*="span"],
  248. .input-prepend input[class*="span"],
  249. .input-prepend .uneditable-input[class*="span"],
  250. .row-fluid input[class*="span"],
  251. .row-fluid select[class*="span"],
  252. .row-fluid textarea[class*="span"],
  253. .row-fluid .uneditable-input[class*="span"],
  254. .row-fluid .input-prepend [class*="span"],
  255. .row-fluid .input-append [class*="span"] {
  256. display: inline-block;
  257. }
  258. // GRID SIZING FOR INPUTS
  259. // ----------------------
  260. // Grid sizes
  261. #grid > .input(@gridColumnWidth, @gridGutterWidth);
  262. // Control row for multiple inputs per line
  263. .controls-row {
  264. .clearfix(); // Clear the float from controls
  265. }
  266. // Float to collapse white-space for proper grid alignment
  267. .controls-row [class*="span"],
  268. // Redeclare the fluid grid collapse since we undo the float for inputs
  269. .row-fluid .controls-row [class*="span"] {
  270. float: left;
  271. }
  272. // Explicity set top padding on all checkboxes/radios, not just first-child
  273. .controls-row .checkbox[class*="span"],
  274. .controls-row .radio[class*="span"] {
  275. padding-top: 5px;
  276. }
  277. // DISABLED STATE
  278. // --------------
  279. // Disabled and read-only inputs
  280. input[disabled],
  281. select[disabled],
  282. textarea[disabled],
  283. input[readonly],
  284. select[readonly],
  285. textarea[readonly] {
  286. cursor: not-allowed;
  287. background-color: @inputDisabledBackground;
  288. }
  289. // Explicitly reset the colors here
  290. input[type="radio"][disabled],
  291. input[type="checkbox"][disabled],
  292. input[type="radio"][readonly],
  293. input[type="checkbox"][readonly] {
  294. background-color: transparent;
  295. }
  296. // FORM FIELD FEEDBACK STATES
  297. // --------------------------
  298. // Warning
  299. .control-group.warning {
  300. .formFieldState(@warningText, @warningText, @warningBackground);
  301. }
  302. // Error
  303. .control-group.error {
  304. .formFieldState(@errorText, @errorText, @errorBackground);
  305. }
  306. // Success
  307. .control-group.success {
  308. .formFieldState(@successText, @successText, @successBackground);
  309. }
  310. // Success
  311. .control-group.info {
  312. .formFieldState(@infoText, @infoText, @infoBackground);
  313. }
  314. // HTML5 invalid states
  315. // Shares styles with the .control-group.error above
  316. input:focus:invalid,
  317. textarea:focus:invalid,
  318. select:focus:invalid {
  319. color: #b94a48;
  320. border-color: #ee5f5b;
  321. &:focus {
  322. border-color: darken(#ee5f5b, 10%);
  323. @shadow: 0 0 6px lighten(#ee5f5b, 20%);
  324. .box-shadow(@shadow);
  325. }
  326. }
  327. // FORM ACTIONS
  328. // ------------
  329. .form-actions {
  330. padding: (@baseLineHeight - 1) 20px @baseLineHeight;
  331. margin-top: @baseLineHeight;
  332. margin-bottom: @baseLineHeight;
  333. background-color: @formActionsBackground;
  334. border-top: 1px solid #e5e5e5;
  335. .clearfix(); // Adding clearfix to allow for .pull-right button containers
  336. }
  337. // HELP TEXT
  338. // ---------
  339. .help-block,
  340. .help-inline {
  341. color: lighten(@textColor, 15%); // lighten the text some for contrast
  342. }
  343. .help-block {
  344. display: block; // account for any element using help-block
  345. margin-bottom: @baseLineHeight / 2;
  346. }
  347. .help-inline {
  348. display: inline-block;
  349. .ie7-inline-block();
  350. vertical-align: middle;
  351. padding-left: 5px;
  352. }
  353. // INPUT GROUPS
  354. // ------------
  355. // Allow us to put symbols and text within the input field for a cleaner look
  356. .input-append,
  357. .input-prepend {
  358. margin-bottom: 5px;
  359. font-size: 0; // white space collapse hack
  360. white-space: nowrap; // Prevent span and input from separating
  361. // Reset the white space collapse hack
  362. input,
  363. select,
  364. .uneditable-input,
  365. .dropdown-menu {
  366. font-size: @baseFontSize;
  367. }
  368. input,
  369. select,
  370. .uneditable-input {
  371. position: relative; // placed here by default so that on :focus we can place the input above the .add-on for full border and box-shadow goodness
  372. margin-bottom: 0; // prevent bottom margin from screwing up alignment in stacked forms
  373. *margin-left: 0;
  374. vertical-align: top;
  375. .border-radius(0 @inputBorderRadius @inputBorderRadius 0);
  376. // Make input on top when focused so blue border and shadow always show
  377. &:focus {
  378. z-index: 2;
  379. }
  380. }
  381. .add-on {
  382. display: inline-block;
  383. width: auto;
  384. height: @baseLineHeight;
  385. min-width: 16px;
  386. padding: 4px 5px;
  387. font-size: @baseFontSize;
  388. font-weight: normal;
  389. line-height: @baseLineHeight;
  390. text-align: center;
  391. text-shadow: 0 1px 0 @white;
  392. background-color: @grayLighter;
  393. border: 1px solid #ccc;
  394. }
  395. .add-on,
  396. .btn,
  397. .btn-group > .dropdown-toggle {
  398. vertical-align: top;
  399. .border-radius(0);
  400. }
  401. .active {
  402. background-color: lighten(@green, 30);
  403. border-color: @green;
  404. }
  405. }
  406. .input-prepend {
  407. .add-on,
  408. .btn {
  409. margin-right: -1px;
  410. }
  411. .add-on:first-child,
  412. .btn:first-child {
  413. // FYI, `.btn:first-child` accounts for a button group that's prepended
  414. .border-radius(@inputBorderRadius 0 0 @inputBorderRadius);
  415. }
  416. }
  417. .input-append {
  418. input,
  419. select,
  420. .uneditable-input {
  421. .border-radius(@inputBorderRadius 0 0 @inputBorderRadius);
  422. + .btn-group .btn:last-child {
  423. .border-radius(0 @inputBorderRadius @inputBorderRadius 0);
  424. }
  425. }
  426. .add-on,
  427. .btn,
  428. .btn-group {
  429. margin-left: -1px;
  430. }
  431. .add-on:last-child,
  432. .btn:last-child,
  433. .btn-group:last-child > .dropdown-toggle {
  434. .border-radius(0 @inputBorderRadius @inputBorderRadius 0);
  435. }
  436. }
  437. // Remove all border-radius for inputs with both prepend and append
  438. .input-prepend.input-append {
  439. input,
  440. select,
  441. .uneditable-input {
  442. .border-radius(0);
  443. + .btn-group .btn {
  444. .border-radius(0 @inputBorderRadius @inputBorderRadius 0);
  445. }
  446. }
  447. .add-on:first-child,
  448. .btn:first-child {
  449. margin-right: -1px;
  450. .border-radius(@inputBorderRadius 0 0 @inputBorderRadius);
  451. }
  452. .add-on:last-child,
  453. .btn:last-child {
  454. margin-left: -1px;
  455. .border-radius(0 @inputBorderRadius @inputBorderRadius 0);
  456. }
  457. .btn-group:first-child {
  458. margin-left: 0;
  459. }
  460. }
  461. // SEARCH FORM
  462. // -----------
  463. input.search-query {
  464. padding-right: 14px;
  465. padding-right: 4px \9;
  466. padding-left: 14px;
  467. padding-left: 4px \9; /* IE7-8 doesn't have border-radius, so don't indent the padding */
  468. margin-bottom: 0; // Remove the default margin on all inputs
  469. .border-radius(15px);
  470. }
  471. /* Allow for input prepend/append in search forms */
  472. .form-search .input-append .search-query,
  473. .form-search .input-prepend .search-query {
  474. .border-radius(0); // Override due to specificity
  475. }
  476. .form-search .input-append .search-query {
  477. .border-radius(14px 0 0 14px);
  478. }
  479. .form-search .input-append .btn {
  480. .border-radius(0 14px 14px 0);
  481. }
  482. .form-search .input-prepend .search-query {
  483. .border-radius(0 14px 14px 0);
  484. }
  485. .form-search .input-prepend .btn {
  486. .border-radius(14px 0 0 14px);
  487. }
  488. // HORIZONTAL & VERTICAL FORMS
  489. // ---------------------------
  490. // Common properties
  491. // -----------------
  492. .form-search,
  493. .form-inline,
  494. .form-horizontal {
  495. input,
  496. textarea,
  497. select,
  498. .help-inline,
  499. .uneditable-input,
  500. .input-prepend,
  501. .input-append {
  502. display: inline-block;
  503. .ie7-inline-block();
  504. margin-bottom: 0;
  505. vertical-align: middle;
  506. }
  507. // Re-hide hidden elements due to specifity
  508. .hide {
  509. display: none;
  510. }
  511. }
  512. .form-search label,
  513. .form-inline label,
  514. .form-search .btn-group,
  515. .form-inline .btn-group {
  516. display: inline-block;
  517. }
  518. // Remove margin for input-prepend/-append
  519. .form-search .input-append,
  520. .form-inline .input-append,
  521. .form-search .input-prepend,
  522. .form-inline .input-prepend {
  523. margin-bottom: 0;
  524. }
  525. // Inline checkbox/radio labels (remove padding on left)
  526. .form-search .radio,
  527. .form-search .checkbox,
  528. .form-inline .radio,
  529. .form-inline .checkbox {
  530. padding-left: 0;
  531. margin-bottom: 0;
  532. vertical-align: middle;
  533. }
  534. // Remove float and margin, set to inline-block
  535. .form-search .radio input[type="radio"],
  536. .form-search .checkbox input[type="checkbox"],
  537. .form-inline .radio input[type="radio"],
  538. .form-inline .checkbox input[type="checkbox"] {
  539. float: left;
  540. margin-right: 3px;
  541. margin-left: 0;
  542. }
  543. // Margin to space out fieldsets
  544. .control-group {
  545. margin-bottom: @baseLineHeight / 2;
  546. }
  547. // Legend collapses margin, so next element is responsible for spacing
  548. legend + .control-group {
  549. margin-top: @baseLineHeight;
  550. -webkit-margin-top-collapse: separate;
  551. }
  552. // Horizontal-specific styles
  553. // --------------------------
  554. .form-horizontal {
  555. // Increase spacing between groups
  556. .control-group {
  557. margin-bottom: @baseLineHeight;
  558. .clearfix();
  559. }
  560. // Float the labels left
  561. .control-label {
  562. float: left;
  563. width: @horizontalComponentOffset - 20;
  564. padding-top: 5px;
  565. text-align: right;
  566. }
  567. // Move over all input controls and content
  568. .controls {
  569. // Super jank IE7 fix to ensure the inputs in .input-append and input-prepend
  570. // don't inherit the margin of the parent, in this case .controls
  571. *display: inline-block;
  572. *padding-left: 20px;
  573. margin-left: @horizontalComponentOffset;
  574. *margin-left: 0;
  575. &:first-child {
  576. *padding-left: @horizontalComponentOffset;
  577. }
  578. }
  579. // Remove bottom margin on block level help text since that's accounted for on .control-group
  580. .help-block {
  581. margin-bottom: 0;
  582. }
  583. // And apply it only to .help-block instances that follow a form control
  584. input,
  585. select,
  586. textarea,
  587. .uneditable-input,
  588. .input-prepend,
  589. .input-append {
  590. + .help-block {
  591. margin-top: @baseLineHeight / 2;
  592. }
  593. }
  594. // Move over buttons in .form-actions to align with .controls
  595. .form-actions {
  596. padding-left: @horizontalComponentOffset;
  597. }
  598. }