_forms.scss 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  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-placeholder-font-color: $steel !default;
  23. $input-font-size: rem-calc(14) !default;
  24. $input-bg-color: $white !default;
  25. $input-focus-bg-color: scale-color($white, $lightness: -2%) !default;
  26. $input-border-color: scale-color($white, $lightness: -20%) !default;
  27. $input-focus-border-color: scale-color($white, $lightness: -40%) !default;
  28. $input-border-style: solid !default;
  29. $input-border-width: 1px !default;
  30. $input-border-radius: $global-radius !default;
  31. $input-disabled-bg: $gainsboro !default;
  32. $input-disabled-cursor: $cursor-default-value !default;
  33. $input-box-shadow: inset 0 1px 2px rgba(0,0,0,0.1) !default;
  34. $input-include-glowing-effect: false !default;
  35. // We use these to style the fieldset border and spacing.
  36. $fieldset-border-style: solid !default;
  37. $fieldset-border-width: 1px !default;
  38. $fieldset-border-color: $gainsboro !default;
  39. $fieldset-padding: rem-calc(20) !default;
  40. $fieldset-margin: rem-calc(18 0) !default;
  41. // We use these to style the legends when you use them
  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. // Disabled 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-left-hidden:true, $border:$input-prefix-border-color, $is-button:false) {
  212. @if $bg {
  213. $bg-lightness: lightness($bg);
  214. background: $bg;
  215. @if $border-left-hidden {
  216. border-#{$default-float}: none;
  217. }
  218. // Control the font color based on background brightness
  219. @if $bg-lightness > 70% or $bg == yellow { color: $input-prefix-font-color; }
  220. @else { color: $input-prefix-font-color-alt; }
  221. }
  222. @if $border {
  223. border-color: $border;
  224. }
  225. @if $is-button {
  226. border: none;
  227. padding-#{$default-float}: 0;
  228. padding-#{$opposite-direction}: 0;
  229. padding-bottom: 0;
  230. padding-top: 0;
  231. text-align: center;
  232. }
  233. }
  234. // We use this mixin to style fieldsets
  235. @mixin fieldset {
  236. border: $fieldset-border-width $fieldset-border-style $fieldset-border-color;
  237. margin: $fieldset-margin;
  238. padding: $fieldset-padding;
  239. // and legend styles
  240. legend {
  241. font-weight: $legend-font-weight;
  242. margin: 0;
  243. margin-#{$default-float}: rem-calc(-3);
  244. padding: $legend-padding;
  245. }
  246. }
  247. // @MIXIN
  248. //
  249. // We use this mixin to control border and background color of error inputs
  250. // $color - Default: $alert-color (found in settings file)
  251. @mixin form-error-color($color:$alert-color) {
  252. background-color: rgba($color, .1);
  253. border-color: $color;
  254. // Go back to normal on focus
  255. &:focus {
  256. background: $input-focus-bg-color;
  257. border-color: $input-focus-border-color;
  258. }
  259. }
  260. // @MIXIN
  261. //
  262. // We use this simple mixin to style labels for error inputs
  263. // $color - Default:$alert-color. Found in settings file
  264. @mixin form-label-error-color($color:$alert-color) { color: $color; }
  265. // @MIXIN
  266. //
  267. // We use this mixin to create error message styles
  268. // $bg - Default: $alert-color (Found in settings file)
  269. @mixin form-error-message($bg:$input-error-message-bg-color) {
  270. display: block;
  271. font-size: $input-error-message-font-size;
  272. font-style: $input-error-message-font-style;
  273. font-weight: $input-error-message-font-weight;
  274. margin-bottom: $form-spacing;
  275. margin-top: $input-error-message-top;
  276. padding: $input-error-message-padding;
  277. // We can control the text color based on the brightness of the background.
  278. $bg-lightness: lightness($bg);
  279. background: $bg;
  280. @if $bg-lightness < 70% or $bg == yellow { color: $input-error-message-font-color; }
  281. @else { color: $input-error-message-font-color-alt; }
  282. }
  283. // We use this mixin to style select elements
  284. @mixin form-select {
  285. -webkit-appearance: none !important;
  286. -moz-appearance: none !important;
  287. background-color: $select-bg-color;
  288. border-radius: 0;
  289. // Hide the dropdown arrow shown in newer IE versions
  290. &::-ms-expand {
  291. display: none;
  292. }
  293. // The custom arrow has some fake horizontal padding so we can align it
  294. // from the right side of the element without relying on CSS3
  295. background-image: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZlcnNpb249IjEuMSIgeD0iMTJweCIgeT0iMHB4IiB3aWR0aD0iMjRweCIgaGVpZ2h0PSIzcHgiIHZpZXdCb3g9IjAgMCA2IDMiIGVuYWJsZS1iYWNrZ3JvdW5kPSJuZXcgMCAwIDYgMyIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+PHBvbHlnb24gcG9pbnRzPSI1Ljk5MiwwIDIuOTkyLDMgLTAuMDA4LDAgIi8+PC9zdmc+');
  296. // We can safely use leftmost and rightmost now
  297. background-position: if($text-direction == 'rtl', 0%, 100%) center;
  298. background-repeat: no-repeat;
  299. border: {
  300. style: $input-border-style;
  301. width: $input-border-width;
  302. color: $input-border-color;
  303. }
  304. color: $input-font-color;
  305. font-family: $input-font-family;
  306. font-size: $input-font-size;
  307. line-height: normal;
  308. padding: ($form-spacing / 2);
  309. @include radius(0);
  310. &.radius { @include radius($global-radius); }
  311. &:focus {
  312. background-color: $select-hover-bg-color;
  313. border-color: $input-focus-border-color;
  314. }
  315. // Disabled Styles
  316. &:disabled {
  317. background-color: $input-disabled-bg;
  318. cursor: $input-disabled-cursor;
  319. }
  320. }
  321. // We use this mixin to turn on/off HTML5 number spinners
  322. @mixin html5number($browser, $on: true) {
  323. @if $on == false {
  324. @if $browser == webkit {
  325. -webkit-appearance: none;
  326. margin: 0;
  327. } @else if $browser == moz {
  328. -moz-appearance: textfield;
  329. }
  330. }
  331. }
  332. @include exports("form") {
  333. @if $include-html-form-classes {
  334. /* Standard Forms */
  335. form { margin: 0 0 $form-spacing; }
  336. /* Using forms within rows, we need to set some defaults */
  337. form .row { @include form-row-base; }
  338. /* Label Styles */
  339. label { @include form-label;
  340. &.right { @include form-label(right, false); }
  341. &.inline { @include form-label(inline, false); }
  342. /* Styles for required inputs */
  343. small {
  344. text-transform: $form-label-small-transform;
  345. color: scale-color($form-label-font-color, $lightness: 15%);
  346. }
  347. }
  348. /* Attach elements to the beginning or end of an input */
  349. .prefix,
  350. .postfix { @include prefix-postfix-base; }
  351. /* Adjust padding, alignment and radius if pre/post element is a button */
  352. .postfix.button { @include button-size(false, false); @include postfix(false, false, false, true); }
  353. .prefix.button { @include button-size(false, false); @include prefix(false, false, true); }
  354. .prefix.button.radius { @include radius(0); @include side-radius($default-float, $button-radius); }
  355. .postfix.button.radius { @include radius(0); @include side-radius($opposite-direction, $button-radius); }
  356. .prefix.button.round { @include radius(0); @include side-radius($default-float, $button-round); }
  357. .postfix.button.round { @include radius(0); @include side-radius($opposite-direction, $button-round); }
  358. /* Separate prefix and postfix styles when on span or label so buttons keep their own */
  359. span.prefix, label.prefix { @include prefix(); }
  360. span.postfix, label.postfix { @include postfix(); }
  361. /* We use this to get basic styling on all basic form elements */
  362. input:not([type]), #{text-inputs(all, 'input')} {
  363. -webkit-appearance: none;
  364. -moz-appearance: none;
  365. border-radius: 0;
  366. @include form-element;
  367. @if $input-include-glowing-effect == false {
  368. -webkit-transition: border-color $input-transition-fade-time $input-transition-fade-timing-function, background $input-transition-fade-time $input-transition-fade-timing-function;
  369. -moz-transition: border-color $input-transition-fade-time $input-transition-fade-timing-function, background $input-transition-fade-time $input-transition-fade-timing-function;
  370. -ms-transition: border-color $input-transition-fade-time $input-transition-fade-timing-function, background $input-transition-fade-time $input-transition-fade-timing-function;
  371. -o-transition: border-color $input-transition-fade-time $input-transition-fade-timing-function, background $input-transition-fade-time $input-transition-fade-timing-function;
  372. transition: border-color $input-transition-fade-time $input-transition-fade-timing-function, background $input-transition-fade-time $input-transition-fade-timing-function;
  373. }
  374. &.radius {
  375. @include radius($input-border-radius);
  376. }
  377. }
  378. form {
  379. .row {
  380. .prefix-radius.row.collapse {
  381. input,
  382. textarea,
  383. select,
  384. button { @include radius(0); @include side-radius($opposite-direction, $button-radius); }
  385. .prefix { @include radius(0); @include side-radius($default-float, $button-radius); }
  386. }
  387. .postfix-radius.row.collapse {
  388. input,
  389. textarea,
  390. select,
  391. button { @include radius(0); @include side-radius($default-float, $button-radius); }
  392. .postfix { @include radius(0); @include side-radius($opposite-direction, $button-radius); }
  393. }
  394. .prefix-round.row.collapse {
  395. input,
  396. textarea,
  397. select,
  398. button { @include radius(0); @include side-radius($opposite-direction, $button-round); }
  399. .prefix { @include radius(0); @include side-radius($default-float, $button-round); }
  400. }
  401. .postfix-round.row.collapse {
  402. input,
  403. textarea,
  404. select,
  405. button { @include radius(0); @include side-radius($default-float, $button-round); }
  406. .postfix { @include radius(0); @include side-radius($opposite-direction, $button-round); }
  407. }
  408. }
  409. }
  410. input[type="submit"] {
  411. -webkit-appearance: none;
  412. -moz-appearance: none;
  413. border-radius: 0;
  414. }
  415. /* Respect enforced amount of rows for textarea */
  416. textarea[rows] {
  417. height: auto;
  418. }
  419. /* Not allow resize out of parent */
  420. textarea {
  421. max-width: 100%;
  422. }
  423. // style placeholder text cross browser
  424. ::-webkit-input-placeholder {
  425. color: $input-placeholder-font-color;
  426. }
  427. :-moz-placeholder { /* Firefox 18- */
  428. color: $input-placeholder-font-color;
  429. }
  430. ::-moz-placeholder { /* Firefox 19+ */
  431. color: $input-placeholder-font-color;
  432. }
  433. :-ms-input-placeholder {
  434. color: $input-placeholder-font-color;
  435. }
  436. /* Add height value for select elements to match text input height */
  437. select {
  438. @include form-select;
  439. height: ($input-font-size + ($form-spacing * 1.5) - rem-calc(1));
  440. &[multiple] {
  441. height: auto;
  442. }
  443. }
  444. /* Adjust margin for form elements below */
  445. input[type="file"],
  446. input[type="checkbox"],
  447. input[type="radio"],
  448. select {
  449. margin: 0 0 $form-spacing 0;
  450. }
  451. input[type="checkbox"] + label,
  452. input[type="radio"] + label {
  453. display: inline-block;
  454. margin-#{$default-float}: $form-spacing * .5;
  455. margin-#{$opposite-direction}: $form-spacing;
  456. margin-bottom: 0;
  457. vertical-align: baseline;
  458. }
  459. /* Normalize file input width */
  460. input[type="file"] {
  461. width:100%;
  462. }
  463. /* HTML5 Number spinners settings */
  464. input[type=number] {
  465. @include html5number(moz, $input-number-spinners)
  466. }
  467. input[type="number"]::-webkit-inner-spin-button,
  468. input[type="number"]::-webkit-outer-spin-button {
  469. @include html5number(webkit, $input-number-spinners);
  470. }
  471. /* We add basic fieldset styling */
  472. fieldset {
  473. @include fieldset;
  474. }
  475. /* Error Handling */
  476. #{data('abide')} {
  477. .error small.error, .error span.error, span.error, small.error {
  478. @include form-error-message;
  479. }
  480. span.error, small.error { display: none; }
  481. }
  482. span.error, small.error {
  483. @include form-error-message;
  484. }
  485. .error {
  486. input,
  487. textarea,
  488. select {
  489. margin-bottom: 0;
  490. }
  491. input[type="checkbox"],
  492. input[type="radio"] {
  493. margin-bottom: $form-spacing
  494. }
  495. label,
  496. label.error {
  497. @include form-label-error-color;
  498. }
  499. small.error {
  500. @include form-error-message;
  501. }
  502. > label {
  503. > small {
  504. background: transparent;
  505. color: scale-color($form-label-font-color, $lightness: 15%);
  506. display: inline;
  507. font-size: 60%;
  508. font-style: normal;
  509. margin: 0;
  510. padding: 0;
  511. text-transform: $form-label-small-transform;
  512. }
  513. }
  514. span.error-message {
  515. display: block;
  516. }
  517. }
  518. input.error,
  519. textarea.error,
  520. select.error {
  521. margin-bottom: 0;
  522. }
  523. label.error { @include form-label-error-color; }
  524. }
  525. }