forms.less 10 KB

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