最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

css - Generating a list of selectors in LESS - Stack Overflow

programmeradmin2浏览0评论

I want to introduce a pseudo-element, say, input-text to be replaced with the following list in any context:

input[type="text"], input[type="search"], input[type="tel"], input[type="url"],
input[type="email"],input[type="password"], input[type="date"],
input[type="month"], input[type="week"], input[type="time"],
input[type="number"], input[type="color"], textarea

For instance:

a
{
    input-text
    {
         …
    }
}

input-text.myclass
{
    …
}

How to achieve this in LESS?

It'd be the best, if I could have a variable, containing the list:

@input-text-selectors: input[type="text"], input[type="search"], input[type="tel"],
    input[type="url"], input[type="email"],input[type="password"], input[type="date"],
    input[type="month"], input[type="week"], input[type="time"], input[type="number"],
    input[type="color"], textarea;

I want to introduce a pseudo-element, say, input-text to be replaced with the following list in any context:

input[type="text"], input[type="search"], input[type="tel"], input[type="url"],
input[type="email"],input[type="password"], input[type="date"],
input[type="month"], input[type="week"], input[type="time"],
input[type="number"], input[type="color"], textarea

For instance:

a
{
    input-text
    {
         …
    }
}

input-text.myclass
{
    …
}

How to achieve this in LESS?

It'd be the best, if I could have a variable, containing the list:

@input-text-selectors: input[type="text"], input[type="search"], input[type="tel"],
    input[type="url"], input[type="email"],input[type="password"], input[type="date"],
    input[type="month"], input[type="week"], input[type="time"], input[type="number"],
    input[type="color"], textarea;
Share Improve this question asked yesterday ShtoleShtole 3501 silver badge15 bronze badges
Add a comment  | 

1 Answer 1

Reset to default -1

So far, the best approach I found is the following:

@text-input: :is(input[type="text"], input[type="search"], input[type="tel"], input[type="url"],
input[type="email"],input[type="password"], input[type="date"],
input[type="month"], input[type="week"], input[type="time"],
input[type="number"], input[type="color"], textarea
);

div > @{text-input} > div // Just for testing, not a real use-case, of course.
{
    color: red;
}

@{text-input}
{
    color: green;
}

It compiles into:

div > :is(input[type="text"], input[type="search"], input[type="tel"], input[type="url"],
input[type="email"],input[type="password"], input[type="date"],
input[type="month"], input[type="week"], input[type="time"],
input[type="number"], input[type="color"], textarea
) > div {
  color: red;
}
:is(input[type="text"], input[type="search"], input[type="tel"], input[type="url"],
input[type="email"],input[type="password"], input[type="date"],
input[type="month"], input[type="week"], input[type="time"],
input[type="number"], input[type="color"], textarea
) {
  color: green;
}

Now I wonder, whether can this be written better.

发布评论

评论列表(0)

  1. 暂无评论