forms.less 9.4 KB

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