_forms.scss 18 KB

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