Last active
May 6, 2020 18:54
-
-
Save mturnwall/9e055b89b374bb429947 to your computer and use it in GitHub Desktop.
SASS mixin for styling input placeholder text
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ---- | |
// libsass (v3.2.5) | |
// ---- | |
/// Style the placeholder attribute of input[type="text"] fields. | |
/// This mixin can be applied globally or on specific text fields | |
/// @example | |
/// // all input and textareas | |
/// @include inputPlaceholder() { | |
/// color: red; | |
/// font-weight: 300; | |
/// padding-top: 5px; | |
/// } | |
/// // just textareas | |
/// textarea { | |
/// @include inputPlaceholder() { | |
/// padding: 15px; | |
/// } | |
/// } | |
/// | |
@mixin inputPlaceholder() { | |
$selector: ''; | |
$prefixes: ( | |
moz: "::-moz", | |
webkit: "::-webkit", | |
ie: ":-ms" | |
); | |
@each $prop, $value in $prefixes { | |
@if $prop != "moz" { | |
$selector: #{$value}-input-placeholder; | |
} @else { | |
$selector: #{$value}-placeholder; | |
} | |
@if & { | |
&#{$selector} { | |
@content; | |
} | |
} @else { | |
#{$selector} { | |
@content; | |
} | |
} | |
} | |
&::placeholder { | |
@content; | |
} | |
} | |
@include inputPlaceholder() { | |
color: red; | |
font-weight: 300; | |
padding-top: 5px; | |
} | |
textarea { | |
@include inputPlaceholder() { | |
padding: 15px; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
::-moz-placeholder { | |
color: red; | |
font-weight: 300; | |
padding-top: 5px; | |
} | |
::-webkit-input-placeholder { | |
color: red; | |
font-weight: 300; | |
padding-top: 5px; | |
} | |
:-ms-input-placeholder { | |
color: red; | |
font-weight: 300; | |
padding-top: 5px; | |
} | |
::placeholder { | |
color: red; | |
font-weight: 300; | |
padding-top: 5px; | |
} | |
textarea::-moz-placeholder { | |
padding: 15px; | |
} | |
textarea::-webkit-input-placeholder { | |
padding: 15px; | |
} | |
textarea:-ms-input-placeholder { | |
padding: 15px; | |
} | |
textarea::placeholder { | |
padding: 15px; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this is great!