可以:not()偽類有多個參數嗎?我正在嘗試選擇除了和之外input的所有元素。typeradiocheckbox很多人已經表明你可以放入多個參數:not,但是使用type似乎無論如何都沒有用到我試試。form input:not([type="radio"], [type="checkbox"]) {
/* css here */}有任何想法嗎?
3 回答

子衿沉夜
TA貢獻1828條經驗 獲得超3個贊
如果您在項目中使用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; }}
它可以以兩種方式使用:
選項1:列出內聯忽略的項目
input { /*non-ignored styling goes here*/ @include not('[type="radio"]','[type="checkbox"]'){ /*ignored styling goes here*/ }}
選項2:首先列出變量中被忽略的項目
$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*/}

紅顏莎娜
TA貢獻1842條經驗 獲得超13個贊
- 3 回答
- 0 關注
- 1003 瀏覽
相關問題推薦
添加回答
舉報
0/150
提交
取消