forms.less.svn-base 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. // Forms.less
  2. // Base styles for various input types, form layouts, and states
  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 * 1.5;
  21. font-size: @baseFontSize * 1.5;
  22. line-height: @baseLineHeight * 2;
  23. color: @grayDark;
  24. border: 0;
  25. border-bottom: 1px solid #eee;
  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. color: @grayDark;
  51. }
  52. // Inputs, Textareas, Selects
  53. input,
  54. textarea,
  55. select,
  56. .uneditable-input {
  57. display: inline-block;
  58. width: 210px;
  59. height: @baseLineHeight;
  60. padding: 4px;
  61. margin-bottom: 9px;
  62. font-size: @baseFontSize;
  63. line-height: @baseLineHeight;
  64. color: @gray;
  65. background-color: @inputBackground;
  66. border: 1px solid @inputBorder;
  67. .border-radius(@inputBorderRadius);
  68. }
  69. .uneditable-textarea {
  70. width: auto;
  71. height: auto;
  72. }
  73. // Inputs within a label
  74. label input,
  75. label textarea,
  76. label select {
  77. display: block;
  78. }
  79. // Mini reset for unique input types
  80. input[type="image"],
  81. input[type="checkbox"],
  82. input[type="radio"] {
  83. width: auto;
  84. height: auto;
  85. padding: 0;
  86. margin: 3px 0;
  87. *margin-top: 0; /* IE7 */
  88. line-height: normal;
  89. cursor: pointer;
  90. background-color: transparent;
  91. border: 0 \9; /* IE9 and down */
  92. .border-radius(0);
  93. }
  94. input[type="image"] {
  95. border: 0;
  96. }
  97. // Reset the file input to browser defaults
  98. input[type="file"] {
  99. width: auto;
  100. padding: initial;
  101. line-height: initial;
  102. background-color: @inputBackground;
  103. background-color: initial;
  104. border: initial;
  105. .box-shadow(none);
  106. }
  107. // Help out input buttons
  108. input[type="button"],
  109. input[type="reset"],
  110. input[type="submit"] {
  111. width: auto;
  112. height: auto;
  113. }
  114. // Set the height of select and file controls to match text inputs
  115. select,
  116. input[type="file"] {
  117. height: 28px; /* In IE7, the height of the select element cannot be changed by height, only font-size */
  118. *margin-top: 4px; /* For IE7, add top margin to align select with labels */
  119. line-height: 28px;
  120. }
  121. // Reset line-height for IE
  122. input[type="file"] {
  123. line-height: 18px \9;
  124. }
  125. // Chrome on Linux and Mobile Safari need background-color
  126. select {
  127. width: 220px; // default input width + 10px of padding that doesn't get applied
  128. background-color: @inputBackground;
  129. }
  130. // Make multiple select elements height not fixed
  131. select[multiple],
  132. select[size] {
  133. height: auto;
  134. }
  135. // Remove shadow from image inputs
  136. input[type="image"] {
  137. .box-shadow(none);
  138. }
  139. // Make textarea height behave
  140. textarea {
  141. height: auto;
  142. }
  143. // Hidden inputs
  144. input[type="hidden"] {
  145. display: none;
  146. }
  147. // CHECKBOXES & RADIOS
  148. // -------------------
  149. // Indent the labels to position radios/checkboxes as hanging
  150. .radio,
  151. .checkbox {
  152. min-height: 18px; // clear the floating input if there is no label text
  153. padding-left: 18px;
  154. }
  155. .radio input[type="radio"],
  156. .checkbox input[type="checkbox"] {
  157. float: left;
  158. margin-left: -18px;
  159. }
  160. // Move the options list down to align with labels
  161. .controls > .radio:first-child,
  162. .controls > .checkbox:first-child {
  163. padding-top: 5px; // has to be padding because margin collaspes
  164. }
  165. // Radios and checkboxes on same line
  166. // TODO v3: Convert .inline to .control-inline
  167. .radio.inline,
  168. .checkbox.inline {
  169. display: inline-block;
  170. padding-top: 5px;
  171. margin-bottom: 0;
  172. vertical-align: middle;
  173. }
  174. .radio.inline + .radio.inline,
  175. .checkbox.inline + .checkbox.inline {
  176. margin-left: 10px; // space out consecutive inline controls
  177. }
  178. // FOCUS STATE
  179. // -----------
  180. input,
  181. textarea {
  182. .box-shadow(inset 0 1px 1px rgba(0,0,0,.075));
  183. @transition: border linear .2s, box-shadow linear .2s;
  184. .transition(@transition);
  185. }
  186. input:focus,
  187. textarea:focus {
  188. border-color: rgba(82,168,236,.8);
  189. outline: 0;
  190. outline: thin dotted \9; /* IE6-9 */
  191. .box-shadow(~"inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(82,168,236,.6)");
  192. }
  193. input[type="file"]:focus,
  194. input[type="radio"]:focus,
  195. input[type="checkbox"]:focus,
  196. select:focus {
  197. .tab-focus();
  198. .box-shadow(none); // override for file inputs
  199. }
  200. // INPUT SIZES
  201. // -----------
  202. // General classes for quick sizes
  203. .input-mini { width: 60px; }
  204. .input-small { width: 90px; }
  205. .input-medium { width: 150px; }
  206. .input-large { width: 210px; }
  207. .input-xlarge { width: 270px; }
  208. .input-xxlarge { width: 530px; }
  209. // Grid style input sizes
  210. input[class*="span"],
  211. select[class*="span"],
  212. textarea[class*="span"],
  213. .uneditable-input[class*="span"],
  214. // Redeclare since the fluid row class is more specific
  215. .row-fluid input[class*="span"],
  216. .row-fluid select[class*="span"],
  217. .row-fluid textarea[class*="span"],
  218. .row-fluid .uneditable-input[class*="span"] {
  219. float: none;
  220. margin-left: 0;
  221. }
  222. // GRID SIZING FOR INPUTS
  223. // ----------------------
  224. #grid > .input (@gridColumnWidth, @gridGutterWidth);
  225. // DISABLED STATE
  226. // --------------
  227. // Disabled and read-only inputs
  228. input[disabled],
  229. select[disabled],
  230. textarea[disabled],
  231. input[readonly],
  232. select[readonly],
  233. textarea[readonly] {
  234. cursor: not-allowed;
  235. background-color: @inputDisabledBackground;
  236. border-color: #ddd;
  237. }
  238. // Explicitly reset the colors here
  239. input[type="radio"][disabled],
  240. input[type="checkbox"][disabled],
  241. input[type="radio"][readonly],
  242. input[type="checkbox"][readonly] {
  243. background-color: transparent;
  244. }
  245. // FORM FIELD FEEDBACK STATES
  246. // --------------------------
  247. // Warning
  248. .control-group.warning {
  249. .formFieldState(@warningText, @warningText, @warningBackground);
  250. }
  251. // Error
  252. .control-group.error {
  253. .formFieldState(@errorText, @errorText, @errorBackground);
  254. }
  255. // Success
  256. .control-group.success {
  257. .formFieldState(@successText, @successText, @successBackground);
  258. }
  259. // HTML5 invalid states
  260. // Shares styles with the .control-group.error above
  261. input:focus:required:invalid,
  262. textarea:focus:required:invalid,
  263. select:focus:required:invalid {
  264. color: #b94a48;
  265. border-color: #ee5f5b;
  266. &:focus {
  267. border-color: darken(#ee5f5b, 10%);
  268. .box-shadow(0 0 6px lighten(#ee5f5b, 20%));
  269. }
  270. }
  271. // FORM ACTIONS
  272. // ------------
  273. .form-actions {
  274. padding: (@baseLineHeight - 1) 20px @baseLineHeight;
  275. margin-top: @baseLineHeight;
  276. margin-bottom: @baseLineHeight;
  277. background-color: @formActionsBackground;
  278. border-top: 1px solid #ddd;
  279. .clearfix(); // Adding clearfix to allow for .pull-right button containers
  280. }
  281. // For text that needs to appear as an input but should not be an input
  282. .uneditable-input {
  283. overflow: hidden; // prevent text from wrapping, but still cut it off like an input does
  284. white-space: nowrap;
  285. cursor: not-allowed;
  286. background-color: @inputBackground;
  287. border-color: #eee;
  288. .box-shadow(inset 0 1px 2px rgba(0,0,0,.025));
  289. }
  290. // Placeholder text gets special styles; can't be bundled together though for some reason
  291. .placeholder(@grayLight);
  292. // HELP TEXT
  293. // ---------
  294. .help-block,
  295. .help-inline {
  296. color: @gray; // lighten the text some for contrast
  297. }
  298. .help-block {
  299. display: block; // account for any element using help-block
  300. margin-bottom: @baseLineHeight / 2;
  301. }
  302. .help-inline {
  303. display: inline-block;
  304. .ie7-inline-block();
  305. vertical-align: middle;
  306. padding-left: 5px;
  307. }
  308. // INPUT GROUPS
  309. // ------------
  310. // Allow us to put symbols and text within the input field for a cleaner look
  311. .input-prepend,
  312. .input-append {
  313. margin-bottom: 5px;
  314. input,
  315. select,
  316. .uneditable-input {
  317. 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
  318. margin-bottom: 0; // prevent bottom margin from screwing up alignment in stacked forms
  319. *margin-left: 0;
  320. vertical-align: middle;
  321. .border-radius(0 @inputBorderRadius @inputBorderRadius 0);
  322. // Make input on top when focused so blue border and shadow always show
  323. &:focus {
  324. z-index: 2;
  325. }
  326. }
  327. .uneditable-input {
  328. border-left-color: #ccc;
  329. }
  330. .add-on {
  331. display: inline-block;
  332. width: auto;
  333. height: @baseLineHeight;
  334. min-width: 16px;
  335. padding: 4px 5px;
  336. font-weight: normal;
  337. line-height: @baseLineHeight;
  338. text-align: center;
  339. text-shadow: 0 1px 0 @white;
  340. vertical-align: middle;
  341. background-color: @grayLighter;
  342. border: 1px solid #ccc;
  343. }
  344. .add-on,
  345. .btn {
  346. margin-left: -1px;
  347. .border-radius(0);
  348. }
  349. .active {
  350. background-color: lighten(@green, 30);
  351. border-color: @green;
  352. }
  353. }
  354. .input-prepend {
  355. .add-on,
  356. .btn {
  357. margin-right: -1px;
  358. }
  359. .add-on:first-child,
  360. .btn:first-child {
  361. .border-radius(@inputBorderRadius 0 0 @inputBorderRadius);
  362. }
  363. }
  364. .input-append {
  365. input,
  366. select,
  367. .uneditable-input {
  368. .border-radius(@inputBorderRadius 0 0 @inputBorderRadius);
  369. }
  370. .uneditable-input {
  371. border-right-color: #ccc;
  372. border-left-color: #eee;
  373. }
  374. .add-on:last-child,
  375. .btn:last-child {
  376. .border-radius(0 @inputBorderRadius @inputBorderRadius 0);
  377. }
  378. }
  379. // Remove all border-radius for inputs with both prepend and append
  380. .input-prepend.input-append {
  381. input,
  382. select,
  383. .uneditable-input {
  384. .border-radius(0);
  385. }
  386. .add-on:first-child,
  387. .btn:first-child {
  388. margin-right: -1px;
  389. .border-radius(@inputBorderRadius 0 0 @inputBorderRadius);
  390. }
  391. .add-on:last-child,
  392. .btn:last-child {
  393. margin-left: -1px;
  394. .border-radius(0 @inputBorderRadius @inputBorderRadius 0);
  395. }
  396. }
  397. // SEARCH FORM
  398. // -----------
  399. .search-query {
  400. padding-right: 14px;
  401. padding-right: 4px \9;
  402. padding-left: 14px;
  403. padding-left: 4px \9; /* IE7-8 doesn't have border-radius, so don't indent the padding */
  404. margin-bottom: 0; // remove the default margin on all inputs
  405. .border-radius(14px);
  406. }
  407. // HORIZONTAL & VERTICAL FORMS
  408. // ---------------------------
  409. // Common properties
  410. // -----------------
  411. .form-search,
  412. .form-inline,
  413. .form-horizontal {
  414. input,
  415. textarea,
  416. select,
  417. .help-inline,
  418. .uneditable-input,
  419. .input-prepend,
  420. .input-append {
  421. display: inline-block;
  422. .ie7-inline-block();
  423. margin-bottom: 0;
  424. }
  425. // Re-hide hidden elements due to specifity
  426. .hide {
  427. display: none;
  428. }
  429. }
  430. .form-search label,
  431. .form-inline label {
  432. display: inline-block;
  433. }
  434. // Remove margin for input-prepend/-append
  435. .form-search .input-append,
  436. .form-inline .input-append,
  437. .form-search .input-prepend,
  438. .form-inline .input-prepend {
  439. margin-bottom: 0;
  440. }
  441. // Inline checkbox/radio labels (remove padding on left)
  442. .form-search .radio,
  443. .form-search .checkbox,
  444. .form-inline .radio,
  445. .form-inline .checkbox {
  446. padding-left: 0;
  447. margin-bottom: 0;
  448. vertical-align: middle;
  449. }
  450. // Remove float and margin, set to inline-block
  451. .form-search .radio input[type="radio"],
  452. .form-search .checkbox input[type="checkbox"],
  453. .form-inline .radio input[type="radio"],
  454. .form-inline .checkbox input[type="checkbox"] {
  455. float: left;
  456. margin-right: 3px;
  457. margin-left: 0;
  458. }
  459. // Margin to space out fieldsets
  460. .control-group {
  461. margin-bottom: @baseLineHeight / 2;
  462. }
  463. // Legend collapses margin, so next element is responsible for spacing
  464. legend + .control-group {
  465. margin-top: @baseLineHeight;
  466. -webkit-margin-top-collapse: separate;
  467. }
  468. // Horizontal-specific styles
  469. // --------------------------
  470. .form-horizontal {
  471. // Increase spacing between groups
  472. .control-group {
  473. margin-bottom: @baseLineHeight;
  474. .clearfix();
  475. }
  476. // Float the labels left
  477. .control-label {
  478. float: left;
  479. width: 140px;
  480. padding-top: 5px;
  481. text-align: right;
  482. }
  483. // Move over all input controls and content
  484. .controls {
  485. // Super jank IE7 fix to ensure the inputs in .input-append and input-prepend
  486. // don't inherit the margin of the parent, in this case .controls
  487. *display: inline-block;
  488. *padding-left: 20px;
  489. margin-left: 160px;
  490. *margin-left: 0;
  491. &:first-child {
  492. *padding-left: 160px;
  493. }
  494. }
  495. // Remove bottom margin on block level help text since that's accounted for on .control-group
  496. .help-block {
  497. margin-top: @baseLineHeight / 2;
  498. margin-bottom: 0;
  499. }
  500. // Move over buttons in .form-actions to align with .controls
  501. .form-actions {
  502. padding-left: 160px;
  503. }
  504. }