Scss/Css Selector to Select All Input Types

I have some input type has this scss setting (from the framework)

textarea,
input[type="text"],
input[type="password"],
input[type="datetime"],
...
input[type="date"],
input[type="month"],
input[type="time"],
input[type="week"],
{
  @include box-shadow(inset 0 1px 1px rgba(0,0,0,.075));
}

I like to override/reset all, something similar

textarea,
input[type="*"],
{
  @include box-shadow(none);
}

above doesn't work, Also

textarea,
    input,
    {
      @include box-shadow(none);
    }

not specific enough. Is there a way to do this than listing all possible types.

Thanks.

3

2 Answers

There are a lot of possible input types. If you want textareas and any input that has a type attribute then...

textarea,
input[type] {
    ...
}

If you want to exclude some input types then use the :not selector. EDIT EXAMPLE JSFIDDLE

textarea,
input[type]:not([type=search]):not([type=url]):not([type=hidden]) {

}

But like I said there are probably a lot more types you DON'T want than types you DO want, so you can't really avoid the list.

You could always use a CSS class instead.

.box-shadowed
{
  @include box-shadow(none);
}
5

Will this suffice?

input[type="text"] {
    border: 1px red;
}

input[type] {
    border: 1px solid blue;
}

They both have the same specificity, so the last one overrides.

See jsFiddle

Another solution would be to ommit the element from the first selector. The latter would have higher specificity – however, you should know that in terms of performance, the first one is similar to using an universal selector (as it attempts to match all elements in the DOM, to check for the attribute).

[type="text"] {
    border: 1px red;
}

input[type="text"] {
    border: 1px solid blue;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Sarah Jenkins

Sarah Jenkins

Senior Technology Editor & AI Specialist

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.

Share this article
Twitter Facebook Pinterest