简体   繁体   中英

How to use attribute selectors for form fields in a SASS/SCSS list variable?

Example:

$list: (
    input[type="text"],
    input[type="name"],
    input[type="email"],
    textarea,
    select[multiple]
) !default;

@each $value in $list {
    #{nth($value, 1)} {
        // Stuff
    }
}

Error (on build using Gulp):

Invalid CSS after "    input": expected expression (e.g. 1px, bold), was '[type="text"],'

Escaping the [ ] like so input\\[type="text"\\] outputs no error yet does not work.

Wrapping the entries with quotations works:

$list: (
    'input[type="text"]',
    'input[type="name"]',
    'input[type="email"]',
    'textarea',
    'select[multiple]'
) !default;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM