:not()伪类能够有多个参数吗?

我试图选择除radiocheckbox以外的全部type s的input元素。 css

许多人代表,您能够在:not多个参数,可是不管如何我尝试都不能使用type浏览器

form input:not([type="radio"], [type="checkbox"]) {
  /* css here */
}

有任何想法吗? 安全


#1楼

我对此有些麻烦,而且“ X:not():not()”方法对我不起做用。 ide

我最终采起了这种策略: this

INPUT {
    /* styles */
}
INPUT[type="radio"], INPUT[type="checkbox"] {
    /* styles that reset previous styles */
}

它几乎没有那么有趣,可是当:not()好战时,它对我有用。 这不是理想的,但很可靠。 spa


#2楼

若是您在项目中使用SASS,则我已经构建了这个mixin以使其按照咱们都但愿的方式工做: 插件

@mixin not($ignorList...) {
    //if only a single value given
    @if (length($ignorList) == 1){
        //it is probably a list variable so set ignore list to the variable
        $ignorList: nth($ignorList,1);
    }
    //set up an empty $notOutput variable
    $notOutput: '';
    //for each item in the list
    @each $not in $ignorList {
        //generate a :not([ignored_item]) segment for each item in the ignore list and put them back to back
        $notOutput: $notOutput + ':not(#{$not})';
    }
    //output the full :not() rule including all ignored items
    &#{$notOutput} {
        @content;
    }
}

它能够以两种方式使用: code

选项1:内联列出被忽略的项目 orm

input {
  /*non-ignored styling goes here*/
  @include not('[type="radio"]','[type="checkbox"]'){
    /*ignored styling goes here*/
  }
}

选项2:首先在变量中列出被忽略的项目 ci

$ignoredItems:
  '[type="radio"]',
  '[type="checkbox"]'
;

input {
  /*non-ignored styling goes here*/
  @include not($ignoredItems){
    /*ignored styling goes here*/
  }
}

任一选项的输出CSS

input {
    /*non-ignored styling goes here*/
}

input:not([type="radio"]):not([type="checkbox"]) {
    /*ignored styling goes here*/
}

#3楼

从CSS 4开始,能够在:not选择器中使用多个参数( 请参阅此处 )。

在CSS3中,:not选择器仅容许1个选择器做为参数。 在4级选择器中,能够将选择器列表做为参数。

例:

/* In this example, all p elements will be red, except for 
   the first child and the ones with the class special. */

p:not(:first-child, .special) {
  color: red;
}

不幸的是,浏览器支持有限 。 目前,它仅适用于Safari。


#4楼

若是安装了“ cssnext” Post CSS插件 ,则能够安全地开始使用如今要使用的语法。

使用cssnext能够打开:

input:not([type="radio"], [type="checkbox"]) {
  /* css here */
}

变成这个:

input:not([type="radio"]):not([type="checkbox"]) {
  /* css here */
}

http://cssnext.io/features/#not-pseudo-class


#5楼

为何:不仅是使用两个:not

input:not([type="radio"]):not([type="checkbox"])

是的,这是故意的

相关文章
相关标签/搜索