Styling a specific set of input types in a reusable way with Sass -
i'd have mixin function returns list of html5 input types. i'd manage in 1 place, , new types come up, change function, not places elsewhere in code.
the problem seems mixins not designed return strings can used outside of curly braces in css. here example of mixin (currently returning errors) , how i'd use it:
/* * set up-and-coming input text types here easier reference * not include types not meant displayed full width, such as: type=number, type=range, type=date, type=color */ @mixin input_text_types( $focus:false ) { @if $focus { @return #{input[type=text]:focus, input[type=password]:focus, input[type=search]:focus, input[type=email]:focus, input[type=url]:focus, input[type=tel]:focus}; } @else { @return #{input[type=text], input[type=password], input[type=search], input[type=email], input[type=url], input[type=tel]}; } } in use:
@include input_text_types() { width: 80%; } the errors error sass/style.scss (line 134 of sass/_functions.scss: invalid css after "...@return #{input": expected "}", "[type=text]:foc...")
i've tried format output , without @return directive, , different ways have seen enclose string values (in quotes, in single quote, in curly braces hash). ever try before?
your problem might better solved using variables contain selectors. using mixin, you're losing ability chain similar elements.
$form-input-text: 'input[type="text"], input[type="password"], input[type="search"], input[type="email"], input[type="tel"], input[type="url"]'; $form-input-buttons: 'input[type="submit"], input[type="reset"], input[type="button"], button'; $form-input-dates: 'input[type^="date"], input[type="month"], input[type="week"], input[type="time"]'; $form-input-not-radio: 'input:not([type="radio"]):not([type="checkbox"])'; #{$form-input-text}, textarea { @include border-radius(.25em); border: $form-input-border; } #{$form-input-text}, textarea, input[type="file"] { width: $form-input-width; max-width: 100%; -webkit-appearance: textfield } #{$form-input-buttons} { padding: .25em .5em; }
Comments
Post a Comment