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

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