You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

forms.less 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  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. .clearfix();
  10. }
  11. fieldset {
  12. padding: 0;
  13. margin: 0;
  14. border: 0;
  15. }
  16. // Groups of fields with labels on top (legends)
  17. legend {
  18. display: block;
  19. width: 100%;
  20. padding: 0;
  21. margin-bottom: @baseLineHeight * 1.5;
  22. font-size: @baseFontSize * 1.5;
  23. line-height: @baseLineHeight * 2;
  24. color: @grayDark;
  25. border: 0;
  26. border-bottom: 1px solid #eee;
  27. }
  28. // Set font for forms
  29. label,
  30. input,
  31. button,
  32. select,
  33. textarea {
  34. #font > .sans-serif(@baseFontSize,normal,@baseLineHeight);
  35. }
  36. // Identify controls by their labels
  37. label {
  38. display: block;
  39. margin-bottom: 5px;
  40. color: @grayDark;
  41. }
  42. // Inputs, Textareas, Selects
  43. input,
  44. textarea,
  45. select,
  46. .uneditable-input {
  47. display: inline-block;
  48. width: 210px;
  49. height: @baseLineHeight;
  50. padding: 4px;
  51. margin-bottom: 9px;
  52. font-size: @baseFontSize;
  53. line-height: @baseLineHeight;
  54. color: @gray;
  55. border: 1px solid #ccc;
  56. .border-radius(3px);
  57. }
  58. .uneditable-textarea {
  59. width: auto;
  60. height: auto;
  61. }
  62. // Inputs within a label
  63. label input,
  64. label textarea,
  65. label select {
  66. display: block;
  67. }
  68. // Mini reset for unique input types
  69. input[type="image"],
  70. input[type="checkbox"],
  71. input[type="radio"] {
  72. width: auto;
  73. height: auto;
  74. padding: 0;
  75. margin: 3px 0;
  76. *margin-top: 0; /* IE7 */
  77. line-height: normal;
  78. border: 0;
  79. cursor: pointer;
  80. .border-radius(0);
  81. }
  82. // Reset the file input to browser defaults
  83. input[type="file"] {
  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. .radio.inline,
  146. .checkbox.inline {
  147. display: inline-block;
  148. margin-bottom: 0;
  149. vertical-align: middle;
  150. }
  151. .radio.inline + .radio.inline,
  152. .checkbox.inline + .checkbox.inline {
  153. margin-left: 10px; // space out consecutive inline controls
  154. }
  155. // But don't forget to remove their padding on first-child
  156. .controls > .radio.inline:first-child,
  157. .controls > .checkbox.inline:first-child {
  158. padding-top: 0;
  159. }
  160. // FOCUS STATE
  161. // -----------
  162. input,
  163. textarea {
  164. .box-shadow(inset 0 1px 1px rgba(0,0,0,.075));
  165. @transition: border linear .2s, box-shadow linear .2s;
  166. .transition(@transition);
  167. }
  168. input:focus,
  169. textarea:focus {
  170. border-color: rgba(82,168,236,.8);
  171. @shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(82,168,236,.6);
  172. .box-shadow(@shadow);
  173. outline: 0;
  174. outline: thin dotted \9; /* IE6-8 */
  175. }
  176. input[type="file"]:focus,
  177. input[type="checkbox"]:focus,
  178. select:focus {
  179. .box-shadow(none); // override for file inputs
  180. .tab-focus();
  181. }
  182. // INPUT SIZES
  183. // -----------
  184. // General classes for quick sizes
  185. .input-mini { width: 60px; }
  186. .input-small { width: 90px; }
  187. .input-medium { width: 150px; }
  188. .input-large { width: 210px; }
  189. .input-xlarge { width: 270px; }
  190. .input-xxlarge { width: 530px; }
  191. // Grid style input sizes
  192. input[class*="span"],
  193. select[class*="span"],
  194. textarea[class*="span"],
  195. .uneditable-input {
  196. float: none;
  197. margin-left: 0;
  198. }
  199. // GRID SIZING FOR INPUTS
  200. // ----------------------
  201. #inputGridSystem > .generate(@gridColumns, @gridColumnWidth, @gridGutterWidth);
  202. // DISABLED STATE
  203. // --------------
  204. // Disabled and read-only inputs
  205. input[disabled],
  206. select[disabled],
  207. textarea[disabled],
  208. input[readonly],
  209. select[readonly],
  210. textarea[readonly] {
  211. background-color: #f5f5f5;
  212. border-color: #ddd;
  213. cursor: not-allowed;
  214. }
  215. // FORM FIELD FEEDBACK STATES
  216. // --------------------------
  217. // Mixin for form field states
  218. .formFieldState(@textColor: #555, @borderColor: #ccc, @backgroundColor: #f5f5f5) {
  219. // Set the text color
  220. > label,
  221. .help-block,
  222. .help-inline {
  223. color: @textColor;
  224. }
  225. // Style inputs accordingly
  226. input,
  227. select,
  228. textarea {
  229. color: @textColor;
  230. border-color: @borderColor;
  231. &:focus {
  232. border-color: darken(@borderColor, 10%);
  233. .box-shadow(0 0 6px lighten(@borderColor, 20%));
  234. }
  235. }
  236. // Give a small background color for input-prepend/-append
  237. .input-prepend .add-on,
  238. .input-append .add-on {
  239. color: @textColor;
  240. background-color: @backgroundColor;
  241. border-color: @textColor;
  242. }
  243. }
  244. // Warning
  245. .control-group.warning {
  246. .formFieldState(@warningText, @warningText, @warningBackground);
  247. }
  248. // Error
  249. .control-group.error {
  250. .formFieldState(@errorText, @errorText, @errorBackground);
  251. }
  252. // Success
  253. .control-group.success {
  254. .formFieldState(@successText, @successText, @successBackground);
  255. }
  256. // HTML5 invalid states
  257. // Shares styles with the .control-group.error above
  258. input:focus:required:invalid,
  259. textarea:focus:required:invalid,
  260. select:focus:required:invalid {
  261. color: #b94a48;
  262. border-color: #ee5f5b;
  263. &:focus {
  264. border-color: darken(#ee5f5b, 10%);
  265. .box-shadow(0 0 6px lighten(#ee5f5b, 20%));
  266. }
  267. }
  268. // FORM ACTIONS
  269. // ------------
  270. .form-actions {
  271. padding: (@baseLineHeight - 1) 20px @baseLineHeight;
  272. margin-top: @baseLineHeight;
  273. margin-bottom: @baseLineHeight;
  274. background-color: #f5f5f5;
  275. border-top: 1px solid #ddd;
  276. }
  277. // For text that needs to appear as an input but should not be an input
  278. .uneditable-input {
  279. display: block;
  280. background-color: @white;
  281. border-color: #eee;
  282. .box-shadow(inset 0 1px 2px rgba(0,0,0,.025));
  283. cursor: not-allowed;
  284. }
  285. // Placeholder text gets special styles; can't be bundled together though for some reason
  286. .placeholder(@grayLight);
  287. // HELP TEXT
  288. // ---------
  289. .help-block {
  290. margin-top: 5px;
  291. margin-bottom: 0;
  292. color: @grayLight;
  293. }
  294. .help-inline {
  295. display: inline-block;
  296. .ie7-inline-block();
  297. margin-bottom: 9px;
  298. vertical-align: middle;
  299. padding-left: 5px;
  300. }
  301. // INPUT GROUPS
  302. // ------------
  303. // Allow us to put symbols and text within the input field for a cleaner look
  304. .input-prepend,
  305. .input-append {
  306. margin-bottom: 5px;
  307. .clearfix(); // Clear the float to prevent wrapping
  308. input,
  309. .uneditable-input {
  310. .border-radius(0 3px 3px 0);
  311. &:focus {
  312. position: relative;
  313. z-index: 2;
  314. }
  315. }
  316. .uneditable-input {
  317. border-left-color: #ccc;
  318. }
  319. .add-on {
  320. float: left;
  321. display: block;
  322. width: auto;
  323. min-width: 16px;
  324. height: @baseLineHeight;
  325. margin-right: -1px;
  326. padding: 4px 5px;
  327. font-weight: normal;
  328. line-height: @baseLineHeight;
  329. color: @grayLight;
  330. text-align: center;
  331. text-shadow: 0 1px 0 @white;
  332. background-color: #f5f5f5;
  333. border: 1px solid #ccc;
  334. .border-radius(3px 0 0 3px);
  335. }
  336. .active {
  337. background-color: lighten(@green, 30);
  338. border-color: @green;
  339. }
  340. }
  341. .input-prepend {
  342. .add-on {
  343. *margin-top: 1px; /* IE6-7 */
  344. }
  345. }
  346. .input-append {
  347. input,
  348. .uneditable-input {
  349. float: left;
  350. .border-radius(3px 0 0 3px);
  351. }
  352. .uneditable-input {
  353. border-right-color: #ccc;
  354. }
  355. .add-on {
  356. margin-right: 0;
  357. margin-left: -1px;
  358. .border-radius(0 3px 3px 0);
  359. }
  360. input:first-child {
  361. // In IE7, having a hasLayout container (from clearfix's zoom:1) can make the first input
  362. // inherit the sum of its ancestors' margins.
  363. *margin-left: -160px;
  364. &+.add-on {
  365. *margin-left: -21px;
  366. }
  367. }
  368. }
  369. // SEARCH FORM
  370. // -----------
  371. .search-query {
  372. padding-left: 14px;
  373. padding-right: 14px;
  374. margin-bottom: 0; // remove the default margin on all inputs
  375. .border-radius(14px);
  376. }
  377. // HORIZONTAL & VERTICAL FORMS
  378. // ---------------------------
  379. // Common properties
  380. // -----------------
  381. .form-search,
  382. .form-inline,
  383. .form-horizontal {
  384. input,
  385. textarea,
  386. select,
  387. .help-inline,
  388. .uneditable-input {
  389. display: inline-block;
  390. margin-bottom: 0;
  391. }
  392. }
  393. .form-search label,
  394. .form-inline label,
  395. .form-search .input-append,
  396. .form-inline .input-append,
  397. .form-search .input-prepend,
  398. .form-inline .input-prepend {
  399. display: inline-block;
  400. }
  401. // Make the prepend and append add-on vertical-align: middle;
  402. .form-search .input-append .add-on,
  403. .form-inline .input-prepend .add-on,
  404. .form-search .input-append .add-on,
  405. .form-inline .input-prepend .add-on {
  406. vertical-align: middle;
  407. }
  408. // Margin to space out fieldsets
  409. .control-group {
  410. margin-bottom: @baseLineHeight / 2;
  411. }
  412. // Horizontal-specific styles
  413. // --------------------------
  414. .form-horizontal {
  415. // Legend collapses margin, so we're relegated to padding
  416. legend + .control-group {
  417. margin-top: @baseLineHeight;
  418. -webkit-margin-top-collapse: separate;
  419. }
  420. // Increase spacing between groups
  421. .control-group {
  422. margin-bottom: @baseLineHeight;
  423. .clearfix();
  424. }
  425. // Float the labels left
  426. .control-group > label {
  427. float: left;
  428. width: 140px;
  429. padding-top: 5px;
  430. text-align: right;
  431. }
  432. // Move over all input controls and content
  433. .controls {
  434. margin-left: 160px;
  435. }
  436. // Move over buttons in .form-actions to align with .controls
  437. .form-actions {
  438. padding-left: 160px;
  439. }
  440. }