_forms.scss 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. // Foundation by ZURB
  2. // foundation.zurb.com
  3. // Licensed under MIT Open Source
  4. @import "global";
  5. @import "buttons";
  6. //
  7. // @variables
  8. //
  9. $include-html-form-classes: $include-html-classes !default;
  10. // We use this to set the base for lots of form spacing and positioning styles
  11. $form-spacing: rem-calc(16) !default;
  12. // We use these to style the labels in different ways
  13. $form-label-pointer: pointer !default;
  14. $form-label-font-size: rem-calc(14) !default;
  15. $form-label-font-weight: $font-weight-normal !default;
  16. $form-label-line-height: 1.5 !default;
  17. $form-label-font-color: scale-color($black, $lightness: 30%) !default;
  18. $form-label-small-transform: capitalize !default;
  19. $form-label-bottom-margin: 0 !default;
  20. $input-font-family: inherit !default;
  21. $input-font-color: rgba(0,0,0,0.75) !default;
  22. $input-font-size: rem-calc(14) !default;
  23. $input-bg-color: $white !default;
  24. $input-focus-bg-color: scale-color($white, $lightness: -2%) !default;
  25. $input-border-color: scale-color($white, $lightness: -20%) !default;
  26. $input-focus-border-color: scale-color($white, $lightness: -40%) !default;
  27. $input-border-style: solid !default;
  28. $input-border-width: 1px !default;
  29. $input-border-radius: $global-radius !default;
  30. $input-disabled-bg: $gainsboro !default;
  31. $input-disabled-cursor: $cursor-default-value !default;
  32. $input-box-shadow: inset 0 1px 2px rgba(0,0,0,0.1) !default;
  33. $input-include-glowing-effect: false !default;
  34. // We use these to style the fieldset border and spacing.
  35. $fieldset-border-style: solid !default;
  36. $fieldset-border-width: 1px !default;
  37. $fieldset-border-color: $gainsboro !default;
  38. $fieldset-padding: rem-calc(20) !default;
  39. $fieldset-margin: rem-calc(18 0) !default;
  40. // We use these to style the legends when you use them
  41. $legend-bg: $white !default;
  42. $legend-font-weight: $font-weight-bold !default;
  43. $legend-padding: rem-calc(0 3) !default;
  44. // We use these to style the prefix and postfix input elements
  45. $input-prefix-bg: scale-color($white, $lightness: -5%) !default;
  46. $input-prefix-border-color: scale-color($white, $lightness: -20%) !default;
  47. $input-prefix-border-size: 1px !default;
  48. $input-prefix-border-type: solid !default;
  49. $input-prefix-overflow: visible !default;
  50. $input-prefix-font-color: $oil !default;
  51. $input-prefix-font-color-alt: $white !default;
  52. // We use this setting to turn on/off HTML5 number spinners (the up/down arrows)
  53. $input-number-spinners: true !default;
  54. // We use these to style the error states for inputs and labels
  55. $input-error-message-padding: rem-calc(6 9 9) !default;
  56. $input-error-message-top: -1px !default;
  57. $input-error-message-font-size: rem-calc(12) !default;
  58. $input-error-message-font-weight: $font-weight-normal !default;
  59. $input-error-message-font-style: italic !default;
  60. $input-error-message-font-color: $white !default;
  61. $input-error-message-bg-color: $alert-color !default;
  62. $input-error-message-font-color-alt: $oil !default;
  63. // We use this to style the glowing effect of inputs when focused
  64. $glowing-effect-fade-time: 0.45s !default;
  65. $glowing-effect-color: $input-focus-border-color !default;
  66. // Select variables
  67. $select-bg-color: $ghost !default;
  68. $select-hover-bg-color: scale-color($select-bg-color, $lightness: -3%) !default;
  69. //
  70. // @MIXINS
  71. //
  72. // We use this mixin to give us form styles for rows inside of forms
  73. @mixin form-row-base {
  74. .row { margin: 0 ((-$form-spacing) / 2);
  75. .column,
  76. .columns { padding: 0 ($form-spacing / 2); }
  77. // Use this to collapse the margins of a form row
  78. &.collapse { margin: 0;
  79. .column,
  80. .columns { padding: 0; }
  81. input {
  82. @include side-radius($opposite-direction, 0);
  83. }
  84. }
  85. }
  86. input.column,
  87. input.columns,
  88. textarea.column,
  89. textarea.columns { padding-#{$default-float}: ($form-spacing / 2); }
  90. }
  91. // @MIXIN
  92. //
  93. // We use this mixin to give all basic form elements their style
  94. @mixin form-element {
  95. background-color: $input-bg-color;
  96. font-family: $input-font-family;
  97. border: {
  98. style: $input-border-style;
  99. width: $input-border-width;
  100. color: $input-border-color;
  101. }
  102. box-shadow: $input-box-shadow;
  103. color: $input-font-color;
  104. display: block;
  105. font-size: $input-font-size;
  106. margin: 0 0 $form-spacing 0;
  107. padding: $form-spacing / 2;
  108. height: ($input-font-size + ($form-spacing * 1.5) - rem-calc(1));
  109. width: 100%;
  110. @include box-sizing(border-box);
  111. @if $input-include-glowing-effect {
  112. @include block-glowing-effect(focus, $glowing-effect-fade-time, $glowing-effect-color);
  113. }
  114. // Basic focus styles
  115. &:focus {
  116. background: $input-focus-bg-color;
  117. border-color: $input-focus-border-color;
  118. outline: none;
  119. }
  120. // Disbaled Styles
  121. &:disabled {
  122. background-color: $input-disabled-bg;
  123. cursor: $input-disabled-cursor;
  124. }
  125. // Disabled background input background color
  126. &[disabled],
  127. &[readonly],
  128. fieldset[disabled] & {
  129. background-color: $input-disabled-bg;
  130. cursor: $input-disabled-cursor;
  131. }
  132. }
  133. // @MIXIN
  134. //
  135. // We use this mixin to create form labels
  136. //
  137. // $alignment - Alignment options. Default: false. Options: [right, inline, false]
  138. // $base-style - Control whether or not the base styles come through. Default: true.
  139. @mixin form-label($alignment:false, $base-style:true) {
  140. // Control whether or not the base styles come through.
  141. @if $base-style {
  142. font-size: $form-label-font-size;
  143. color: $form-label-font-color;
  144. cursor: $form-label-pointer;
  145. display: block;
  146. font-weight: $form-label-font-weight;
  147. line-height: $form-label-line-height;
  148. margin-bottom: $form-label-bottom-margin;
  149. }
  150. // Alignment options
  151. @if $alignment == right {
  152. float: none !important;
  153. text-align: right;
  154. }
  155. @else if $alignment == inline {
  156. margin: 0 0 $form-spacing 0;
  157. padding: $form-spacing / 2 + rem-calc($input-border-width) 0;
  158. }
  159. }
  160. // We use this mixin to create postfix/prefix form Labels
  161. @mixin prefix-postfix-base {
  162. display: block;
  163. position: relative;
  164. z-index: 2;
  165. text-align: center;
  166. width: 100%;
  167. padding-top: 0;
  168. padding-bottom: 0;
  169. border-style: $input-prefix-border-type;
  170. border-width: $input-prefix-border-size;
  171. overflow: $input-prefix-overflow;
  172. font-size: $form-label-font-size;
  173. height: ($input-font-size + ($form-spacing * 1.5) - rem-calc(1));
  174. line-height: ($input-font-size + ($form-spacing * 1.5) - rem-calc(1));
  175. }
  176. // @MIXIN
  177. //
  178. // We use this mixin to create prefix label styles
  179. // $bg - Default:$input-prefix-bg || scale-color($white, $lightness: -5%) !default;
  180. // $is-button - Toggle position settings if prefix is a button. Default:false
  181. //
  182. @mixin prefix($bg:$input-prefix-bg, $border:$input-prefix-border-color, $is-button:false) {
  183. @if $bg {
  184. $bg-lightness: lightness($bg);
  185. background: $bg;
  186. border-#{$opposite-direction}: none;
  187. // Control the font color based on background brightness
  188. @if $bg-lightness > 70% or $bg == yellow { color: $input-prefix-font-color; }
  189. @else { color: $input-prefix-font-color-alt; }
  190. }
  191. @if $border {
  192. border-color: $border;
  193. }
  194. @if $is-button {
  195. padding-#{$default-float}: 0;
  196. padding-#{$opposite-direction}: 0;
  197. padding-top: 0;
  198. padding-bottom: 0;
  199. text-align: center;
  200. border: none;
  201. }
  202. }
  203. // @MIXIN
  204. //
  205. // We use this mixin to create postfix label styles
  206. // $bg - Default:$input-prefix-bg || scale-color($white, $lightness: -5%) !default;
  207. // $is-button - Toggle position settings if prefix is a button. Default: false
  208. @mixin postfix($bg:$input-prefix-bg, $border:$input-prefix-border-color, $is-button:false) {
  209. @if $bg {
  210. $bg-lightness: lightness($bg);
  211. background: $bg;
  212. border-#{$default-float}: none;
  213. // Control the font color based on background brightness
  214. @if $bg-lightness > 70% or $bg == yellow { color: $input-prefix-font-color; }
  215. @else { color: $input-prefix-font-color-alt; }
  216. }
  217. @if $border {
  218. border-color: $border;
  219. }
  220. @if $is-button {
  221. padding-#{$default-float}: 0;
  222. padding-#{$opposite-direction}: 0;
  223. padding-top: 0;
  224. padding-bottom: 0;
  225. text-align: center;
  226. border: none;
  227. }
  228. }
  229. // We use this mixin to style fieldsets
  230. @mixin fieldset {
  231. border: $fieldset-border-width $fieldset-border-style $fieldset-border-color;
  232. padding: $fieldset-padding;
  233. margin: $fieldset-margin;
  234. // and legend styles
  235. legend {
  236. font-weight: $legend-font-weight;
  237. background: $legend-bg;
  238. padding: $legend-padding;
  239. margin: 0;
  240. margin-#{$default-float}: rem-calc(-3);
  241. }
  242. }
  243. // @MIXIN
  244. //
  245. // We use this mixin to control border and background color of error inputs
  246. // $color - Default: $alert-color (found in settings file)
  247. @mixin form-error-color($color:$alert-color) {
  248. border-color: $color;
  249. background-color: rgba($color, 0.1);
  250. // Go back to normal on focus
  251. &:focus {
  252. background: $input-focus-bg-color;
  253. border-color: $input-focus-border-color;
  254. }
  255. }
  256. // @MIXIN
  257. //
  258. // We use this simple mixin to style labels for error inputs
  259. // $color - Default:$alert-color. Found in settings file
  260. @mixin form-label-error-color($color:$alert-color) { color: $color; }
  261. // @MIXIN
  262. //
  263. // We use this mixin to create error message styles
  264. // $bg - Default: $alert-color (Found in settings file)
  265. @mixin form-error-message($bg:$input-error-message-bg-color) {
  266. display: block;
  267. padding: $input-error-message-padding;
  268. margin-top: $input-error-message-top;
  269. margin-bottom: $form-spacing;
  270. font-size: $input-error-message-font-size;
  271. font-weight: $input-error-message-font-weight;
  272. font-style: $input-error-message-font-style;
  273. // We can control the text color based on the brightness of the background.
  274. $bg-lightness: lightness($bg);
  275. background: $bg;
  276. @if $bg-lightness < 70% or $bg == yellow { color: $input-error-message-font-color; }
  277. @else { color: $input-error-message-font-color-alt; }
  278. }
  279. // We use this mixin to style select elements
  280. @mixin form-select {
  281. -webkit-appearance: none !important;
  282. border-radius: 0;
  283. background-color: $select-bg-color;
  284. // Hide the dropdown arrow shown in newer IE versions
  285. &::-ms-expand {
  286. display: none;
  287. }
  288. // The custom arrow has some fake horizontal padding so we can align it
  289. // from the right side of the element without relying on CSS3
  290. background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZlcnNpb249IjEuMSIgeD0iMTJweCIgeT0iMHB4IiB3aWR0aD0iMjRweCIgaGVpZ2h0PSIzcHgiIHZpZXdCb3g9IjAgMCA2IDMiIGVuYWJsZS1iYWNrZ3JvdW5kPSJuZXcgMCAwIDYgMyIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+PHBvbHlnb24gcG9pbnRzPSI1Ljk5MiwwIDIuOTkyLDMgLTAuMDA4LDAgIi8+PC9zdmc+);
  291. // We can safely use leftmost and rightmost now
  292. background-position: if($text-direction == 'rtl', 0%, 100%) center;
  293. background-repeat: no-repeat;
  294. border: {
  295. style: $input-border-style;
  296. width: $input-border-width;
  297. color: $input-border-color;
  298. }
  299. padding: ($form-spacing / 2);
  300. font-size: $input-font-size;
  301. font-family: $body-font-family;
  302. color: $input-font-color;
  303. line-height: normal;
  304. @include radius(0);
  305. &.radius { @include radius($global-radius); }
  306. &:hover {
  307. background-color: $select-hover-bg-color;
  308. border-color: $input-focus-border-color;
  309. }
  310. // Disabled Styles
  311. &:disabled {
  312. background-color: $input-disabled-bg;
  313. cursor: $input-disabled-cursor;
  314. }
  315. }
  316. // We use this mixin to turn on/off HTML5 number spinners
  317. @mixin html5number($browser, $on:true) {
  318. @if $on==false {
  319. @if $browser==webkit {
  320. -webkit-appearance: none;
  321. margin: 0;
  322. } @else if $browser==moz {
  323. -moz-appearance: textfield;
  324. }
  325. }
  326. }
  327. @include exports("form") {
  328. @if $include-html-form-classes {
  329. /* Standard Forms */
  330. form { margin: 0 0 $form-spacing; }
  331. /* Using forms within rows, we need to set some defaults */
  332. form .row { @include form-row-base; }
  333. /* Label Styles */
  334. label { @include form-label;
  335. &.right { @include form-label(right,false); }
  336. &.inline { @include form-label(inline,false); }
  337. /* Styles for required inputs */
  338. small {
  339. text-transform: $form-label-small-transform;
  340. color: scale-color($form-label-font-color, $lightness: 15%);
  341. }
  342. }
  343. /* Attach elements to the beginning or end of an input */
  344. .prefix,
  345. .postfix { @include prefix-postfix-base; }
  346. /* Adjust padding, alignment and radius if pre/post element is a button */
  347. .postfix.button { @include button-size(false,false); @include postfix(false, false, true); }
  348. .prefix.button { @include button-size(false,false); @include prefix(false, false, true); }
  349. .prefix.button.radius { @include radius(0); @include side-radius($default-float, $button-radius); }
  350. .postfix.button.radius { @include radius(0); @include side-radius($opposite-direction, $button-radius); }
  351. .prefix.button.round { @include radius(0); @include side-radius($default-float, $button-round); }
  352. .postfix.button.round { @include radius(0); @include side-radius($opposite-direction, $button-round); }
  353. /* Separate prefix and postfix styles when on span or label so buttons keep their own */
  354. span.prefix,label.prefix { @include prefix(); }
  355. span.postfix,label.postfix { @include postfix(); }
  356. /* We use this to get basic styling on all basic form elements */
  357. #{text-inputs(all, 'input')} {
  358. -webkit-appearance: none;
  359. border-radius: 0;
  360. @include form-element;
  361. @if $input-include-glowing-effect == false {
  362. @include single-transition(all, 0.15s, linear);
  363. }
  364. &.radius {
  365. @include radius($input-border-radius);
  366. }
  367. }
  368. form {
  369. .row {
  370. .prefix-radius.row.collapse {
  371. input,
  372. textarea,
  373. select,
  374. button { @include radius(0); @include side-radius($opposite-direction, $button-radius); }
  375. .prefix { @include radius(0); @include side-radius($default-float, $button-radius); }
  376. }
  377. .postfix-radius.row.collapse {
  378. input,
  379. textarea,
  380. select,
  381. button { @include radius(0); @include side-radius($default-float, $button-radius); }
  382. .postfix { @include radius(0); @include side-radius($opposite-direction, $button-radius); }
  383. }
  384. .prefix-round.row.collapse {
  385. input,
  386. textarea,
  387. select,
  388. button { @include radius(0); @include side-radius($opposite-direction, $button-round); }
  389. .prefix { @include radius(0); @include side-radius($default-float, $button-round); }
  390. }
  391. .postfix-round.row.collapse {
  392. input,
  393. textarea,
  394. select,
  395. button { @include radius(0); @include side-radius($default-float, $button-round); }
  396. .postfix { @include radius(0); @include side-radius($opposite-direction, $button-round); }
  397. }
  398. }
  399. }
  400. input[type="submit"] {
  401. -webkit-appearance: none;
  402. border-radius: 0;
  403. }
  404. /* Respect enforced amount of rows for textarea */
  405. textarea[rows] {
  406. height: auto;
  407. }
  408. /* Not allow resize out of parent */
  409. textarea {
  410. max-width: 100%;
  411. }
  412. /* Add height value for select elements to match text input height */
  413. select {
  414. @include form-select;
  415. height: ($input-font-size + ($form-spacing * 1.5) - rem-calc(1));
  416. &[multiple] {
  417. height: auto;
  418. }
  419. }
  420. /* Adjust margin for form elements below */
  421. input[type="file"],
  422. input[type="checkbox"],
  423. input[type="radio"],
  424. select {
  425. margin: 0 0 $form-spacing 0;
  426. }
  427. input[type="checkbox"] + label,
  428. input[type="radio"] + label {
  429. display: inline-block;
  430. margin-#{$default-float}: $form-spacing * .5;
  431. margin-#{$opposite-direction}: $form-spacing;
  432. margin-bottom: 0;
  433. vertical-align: baseline;
  434. }
  435. /* Normalize file input width */
  436. input[type="file"] {
  437. width:100%;
  438. }
  439. /* HTML5 Number spinners settings */
  440. input[type=number] {
  441. @include html5number(moz, $input-number-spinners)
  442. }
  443. input[type="number"]::-webkit-inner-spin-button,
  444. input[type="number"]::-webkit-outer-spin-button {
  445. @include html5number(webkit, $input-number-spinners);
  446. }
  447. /* We add basic fieldset styling */
  448. fieldset {
  449. @include fieldset;
  450. }
  451. /* Error Handling */
  452. #{data('abide')} {
  453. .error small.error, .error span.error, span.error, small.error {
  454. @include form-error-message;
  455. }
  456. span.error, small.error { display: none; }
  457. }
  458. span.error, small.error {
  459. @include form-error-message;
  460. }
  461. .error {
  462. input,
  463. textarea,
  464. select {
  465. margin-bottom: 0;
  466. }
  467. input[type="checkbox"],
  468. input[type="radio"] {
  469. margin-bottom: $form-spacing
  470. }
  471. label,
  472. label.error {
  473. @include form-label-error-color;
  474. }
  475. small.error {
  476. @include form-error-message;
  477. }
  478. > label {
  479. > small {
  480. color: scale-color($form-label-font-color, $lightness: 15%);
  481. background: transparent;
  482. padding: 0;
  483. text-transform: $form-label-small-transform;
  484. font-style: normal;
  485. font-size: 60%;
  486. margin: 0;
  487. display: inline;
  488. }
  489. }
  490. span.error-message {
  491. display: block;
  492. }
  493. }
  494. input.error,
  495. textarea.error,
  496. select.error {
  497. margin-bottom: 0;
  498. }
  499. label.error { @include form-label-error-color; }
  500. }
  501. }