31

我有一些输入类型有这个 scss 设置(来自框架)

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));
}

我喜欢覆盖/重置所有,类似的东西

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

以上不起作用,还有

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

不够具体。除了列出所有可能的类型之外,有没有办法做到这一点。

谢谢。

4

2 回答 2

52

有很多可能的输入类型。如果您想要 textareas 和任何具有 type 属性的输入,那么...

textarea,
input[type] {
    ...
}

如果要排除某些输入类型,请使用:not选择器。 编辑示例 JSFIDDLE http://jsfiddle.net/Pnbb8/

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

}

但就像我说的那样,你不想要的类型可能比你想要的类型多得多,所以你不能真正避免这个列表。

您总是可以使用 CSS 类。

.box-shadowed
{
  @include box-shadow(none);
}
于 2013-08-06T16:14:30.297 回答
7

这足够了吗?

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

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

它们都具有相同的特异性,因此最后一个覆盖。

见 jsFiddle

另一种解决方案是省略第一个选择器中的元素。后者将具有更高的特异性——但是,您应该知道,就性能而言,第一个类似于使用通用选择器(因为它尝试匹配 DOM 中的所有元素,以检查属性)。

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

input[type="text"] {
    border: 1px solid blue;
}
于 2013-08-06T16:30:28.213 回答