forms.less 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  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: 9px;
  75. font-size: @baseFontSize;
  76. line-height: @baseLineHeight;
  77. color: @gray;
  78. .border-radius(@inputBorderRadius);
  79. }
  80. // Reset appearance properties for textual inputs and textarea
  81. // Declare width for legacy (can't be on input[type=*] selectors or it's too specific)
  82. input,
  83. textarea,
  84. .uneditable-input {
  85. width: 206px; // plus 12px padding and 2px border
  86. }
  87. // Reset height since textareas have rows
  88. textarea {
  89. height: auto;
  90. }
  91. // Everything else
  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. .uneditable-input {
  108. background-color: @inputBackground;
  109. border: 1px solid @inputBorder;
  110. .box-shadow(inset 0 1px 1px rgba(0,0,0,.075));
  111. .transition(~"border linear .2s, box-shadow linear .2s");
  112. // Focus state
  113. &:focus {
  114. border-color: rgba(82,168,236,.8);
  115. outline: 0;
  116. outline: thin dotted \9; /* IE6-9 */
  117. .box-shadow(inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(82,168,236,.6));
  118. }
  119. }
  120. // Position radios and checkboxes better
  121. input[type="radio"],
  122. input[type="checkbox"] {
  123. margin: 4px 0 0;
  124. *margin-top: 0; /* IE7 */
  125. margin-top: 1px \9; /* IE8-9 */
  126. line-height: normal;
  127. cursor: pointer;
  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: 30px; /* 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: 30px;
  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: 18px; // clear the floating input if there is no label text
  198. padding-left: 18px;
  199. }
  200. .radio input[type="radio"],
  201. .checkbox input[type="checkbox"] {
  202. float: left;
  203. margin-left: -18px;
  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. .controls-row [class*="span"] {
  267. float: left; // Float to collapse white-space for proper grid alignment
  268. }
  269. // DISABLED STATE
  270. // --------------
  271. // Disabled and read-only inputs
  272. input[disabled],
  273. select[disabled],
  274. textarea[disabled],
  275. input[readonly],
  276. select[readonly],
  277. textarea[readonly] {
  278. cursor: not-allowed;
  279. background-color: @inputDisabledBackground;
  280. }
  281. // Explicitly reset the colors here
  282. input[type="radio"][disabled],
  283. input[type="checkbox"][disabled],
  284. input[type="radio"][readonly],
  285. input[type="checkbox"][readonly] {
  286. background-color: transparent;
  287. }
  288. // FORM FIELD FEEDBACK STATES
  289. // --------------------------
  290. // Warning
  291. .control-group.warning {
  292. .formFieldState(@warningText, @warningText, @warningBackground);
  293. }
  294. // Error
  295. .control-group.error {
  296. .formFieldState(@errorText, @errorText, @errorBackground);
  297. }
  298. // Success
  299. .control-group.success {
  300. .formFieldState(@successText, @successText, @successBackground);
  301. }
  302. // Success
  303. .control-group.info {
  304. .formFieldState(@infoText, @infoText, @infoBackground);
  305. }
  306. // HTML5 invalid states
  307. // Shares styles with the .control-group.error above
  308. input:focus:required:invalid,
  309. textarea:focus:required:invalid,
  310. select:focus:required:invalid {
  311. color: #b94a48;
  312. border-color: #ee5f5b;
  313. &:focus {
  314. border-color: darken(#ee5f5b, 10%);
  315. .box-shadow(0 0 6px lighten(#ee5f5b, 20%));
  316. }
  317. }
  318. // FORM ACTIONS
  319. // ------------
  320. .form-actions {
  321. padding: (@baseLineHeight - 1) 20px @baseLineHeight;
  322. margin-top: @baseLineHeight;
  323. margin-bottom: @baseLineHeight;
  324. background-color: @formActionsBackground;
  325. border-top: 1px solid #e5e5e5;
  326. .clearfix(); // Adding clearfix to allow for .pull-right button containers
  327. }
  328. // HELP TEXT
  329. // ---------
  330. .help-block,
  331. .help-inline {
  332. color: lighten(@textColor, 15%); // lighten the text some for contrast
  333. }
  334. .help-block {
  335. display: block; // account for any element using help-block
  336. margin-bottom: @baseLineHeight / 2;
  337. }
  338. .help-inline {
  339. display: inline-block;
  340. .ie7-inline-block();
  341. vertical-align: middle;
  342. padding-left: 5px;
  343. }
  344. // INPUT GROUPS
  345. // ------------
  346. // Allow us to put symbols and text within the input field for a cleaner look
  347. .input-append,
  348. .input-prepend {
  349. margin-bottom: 5px;
  350. font-size: 0;
  351. white-space: nowrap; // Prevent span and input from separating
  352. input,
  353. select,
  354. .uneditable-input {
  355. 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
  356. margin-bottom: 0; // prevent bottom margin from screwing up alignment in stacked forms
  357. *margin-left: 0;
  358. font-size: @baseFontSize;
  359. vertical-align: top;
  360. .border-radius(0 @inputBorderRadius @inputBorderRadius 0);
  361. // Make input on top when focused so blue border and shadow always show
  362. &:focus {
  363. z-index: 2;
  364. }
  365. }
  366. .add-on {
  367. display: inline-block;
  368. width: auto;
  369. height: @baseLineHeight;
  370. min-width: 16px;
  371. padding: 4px 5px;
  372. font-size: @baseFontSize;
  373. font-weight: normal;
  374. line-height: @baseLineHeight;
  375. text-align: center;
  376. text-shadow: 0 1px 0 @white;
  377. background-color: @grayLighter;
  378. border: 1px solid #ccc;
  379. }
  380. .add-on,
  381. .btn {
  382. vertical-align: top;
  383. .border-radius(0);
  384. }
  385. .active {
  386. background-color: lighten(@green, 30);
  387. border-color: @green;
  388. }
  389. }
  390. .input-prepend {
  391. .add-on,
  392. .btn {
  393. margin-right: -1px;
  394. }
  395. .add-on:first-child,
  396. .btn:first-child {
  397. .border-radius(@inputBorderRadius 0 0 @inputBorderRadius);
  398. }
  399. }
  400. .input-append {
  401. input,
  402. select,
  403. .uneditable-input {
  404. .border-radius(@inputBorderRadius 0 0 @inputBorderRadius);
  405. }
  406. .add-on,
  407. .btn {
  408. margin-left: -1px;
  409. }
  410. .add-on:last-child,
  411. .btn:last-child {
  412. .border-radius(0 @inputBorderRadius @inputBorderRadius 0);
  413. }
  414. }
  415. // Remove all border-radius for inputs with both prepend and append
  416. .input-prepend.input-append {
  417. input,
  418. select,
  419. .uneditable-input {
  420. .border-radius(0);
  421. }
  422. .add-on:first-child,
  423. .btn:first-child {
  424. margin-right: -1px;
  425. .border-radius(@inputBorderRadius 0 0 @inputBorderRadius);
  426. }
  427. .add-on:last-child,
  428. .btn:last-child {
  429. margin-left: -1px;
  430. .border-radius(0 @inputBorderRadius @inputBorderRadius 0);
  431. }
  432. }
  433. // SEARCH FORM
  434. // -----------
  435. input.search-query {
  436. padding-right: 14px;
  437. padding-right: 4px \9;
  438. padding-left: 14px;
  439. padding-left: 4px \9; /* IE7-8 doesn't have border-radius, so don't indent the padding */
  440. margin-bottom: 0; // Remove the default margin on all inputs
  441. .border-radius(15px);
  442. }
  443. /* Allow for input prepend/append in search forms */
  444. .form-search .input-append .search-query,
  445. .form-search .input-prepend .search-query {
  446. .border-radius(0); // Override due to specificity
  447. }
  448. .form-search .input-append .search-query {
  449. .border-radius(14px 0 0 14px);
  450. }
  451. .form-search .input-append .btn {
  452. .border-radius(0 14px 14px 0);
  453. }
  454. .form-search .input-prepend .search-query {
  455. .border-radius(0 14px 14px 0);
  456. }
  457. .form-search .input-prepend .btn {
  458. .border-radius(14px 0 0 14px);
  459. }
  460. // HORIZONTAL & VERTICAL FORMS
  461. // ---------------------------
  462. // Common properties
  463. // -----------------
  464. .form-search,
  465. .form-inline,
  466. .form-horizontal {
  467. input,
  468. textarea,
  469. select,
  470. .help-inline,
  471. .uneditable-input,
  472. .input-prepend,
  473. .input-append {
  474. display: inline-block;
  475. .ie7-inline-block();
  476. margin-bottom: 0;
  477. vertical-align: middle;
  478. }
  479. // Re-hide hidden elements due to specifity
  480. .hide {
  481. display: none;
  482. }
  483. }
  484. .form-search label,
  485. .form-inline label,
  486. .form-search .btn-group,
  487. .form-inline .btn-group {
  488. display: inline-block;
  489. }
  490. // Remove margin for input-prepend/-append
  491. .form-search .input-append,
  492. .form-inline .input-append,
  493. .form-search .input-prepend,
  494. .form-inline .input-prepend {
  495. margin-bottom: 0;
  496. }
  497. // Inline checkbox/radio labels (remove padding on left)
  498. .form-search .radio,
  499. .form-search .checkbox,
  500. .form-inline .radio,
  501. .form-inline .checkbox {
  502. padding-left: 0;
  503. margin-bottom: 0;
  504. vertical-align: middle;
  505. }
  506. // Remove float and margin, set to inline-block
  507. .form-search .radio input[type="radio"],
  508. .form-search .checkbox input[type="checkbox"],
  509. .form-inline .radio input[type="radio"],
  510. .form-inline .checkbox input[type="checkbox"] {
  511. float: left;
  512. margin-right: 3px;
  513. margin-left: 0;
  514. }
  515. // Margin to space out fieldsets
  516. .control-group {
  517. margin-bottom: @baseLineHeight / 2;
  518. }
  519. // Legend collapses margin, so next element is responsible for spacing
  520. legend + .control-group {
  521. margin-top: @baseLineHeight;
  522. -webkit-margin-top-collapse: separate;
  523. }
  524. // Horizontal-specific styles
  525. // --------------------------
  526. .form-horizontal {
  527. // Increase spacing between groups
  528. .control-group {
  529. margin-bottom: @baseLineHeight;
  530. .clearfix();
  531. }
  532. // Float the labels left
  533. .control-label {
  534. float: left;
  535. width: @horizontalComponentOffset - 20;
  536. padding-top: 5px;
  537. text-align: right;
  538. }
  539. // Move over all input controls and content
  540. .controls {
  541. // Super jank IE7 fix to ensure the inputs in .input-append and input-prepend
  542. // don't inherit the margin of the parent, in this case .controls
  543. *display: inline-block;
  544. *padding-left: 20px;
  545. margin-left: @horizontalComponentOffset;
  546. *margin-left: 0;
  547. &:first-child {
  548. *padding-left: @horizontalComponentOffset;
  549. }
  550. }
  551. // Remove bottom margin on block level help text since that's accounted for on .control-group
  552. .help-block {
  553. margin-bottom: 0;
  554. }
  555. // And apply it only to .help-block instances that follow a form control
  556. input,
  557. select,
  558. textarea {
  559. + .help-block {
  560. margin-top: @baseLineHeight / 2;
  561. }
  562. }
  563. // Move over buttons in .form-actions to align with .controls
  564. .form-actions {
  565. padding-left: @horizontalComponentOffset;
  566. }
  567. }