CSS @supports(:: pseudo-element)

时间:2016-01-25 19:37:43

标签: css css-selectors pseudo-element

我想将区域更改为最大溢出:仅在支持::-webkit-scrollbar-thumb时滚动。

这在纯CSS中是否有可能?看起来@supports只检查规则,没有选择器。

4 个答案:

答案 0 :(得分:4)

你是对的。 public class MatchNutsBolts { public static void main(String[] args) { // TODO Auto-generated method stub Random r = new Random(20); Bolt[] listOfBolts = NutsBolts.makeRandomBolts(r, 7); Nut[] listOfNuts = NutsBolts.makeMatchingNuts(r, listOfBolts); int low = 0; int hi = listOfBolts.length-1; match(listOfNuts, listOfBolts, low, hi); boolean x = NutsBolts.correctFit(listOfNuts, listOfBolts); System.out.print(x+" "); } public static void match(Nut[] nut, Bolt[] bolt, int low, int hi) { if (low < hi) { // Choose last character of bolts array for nuts partition. int pivot = partition(nut, low, hi, bolt[hi]); //here is where im having a problem // Now using the partition of nuts choose that for bolts // partition. partition(bolt, low, hi, nut[pivot]); match(nut, bolt, low, pivot-1); match(nut, bolt, pivot+1, hi); } } private static int partition(Bolt[] bolt, int low, int high, Nut pivot) { int i = low; Bolt temp1, temp2; for (int j = low; j < high; j++) { //int cmp = Nut.compareTo(bolt[j]); if (bolt[j].getDigit(i) < pivot.getDigit(i)){ temp1 = bolt[i]; bolt[i] = bolt[j]; bolt[j] = temp1; i++; } else if(bolt[j].getDigit(i) == pivot.getDigit(i)){ temp1 = bolt[j]; bolt[j] = bolt[high]; bolt[high] = temp1; j--; } } temp2 = bolt[i]; bolt[i] = bolt[high]; bolt[high] = temp2; // Return the partition index of an array based on the pivot // element of other array. return i; } } class Bolt { final private static int SIZE = 7; private int[] notches; // A Bolt object is basically a seven digit number. public Bolt(Random r) { notches = new int[SIZE]; for (int i=0; i<notches.length; i++) notches[i] = r.nextInt(10); } // A standard constructor given the information stored in a Bolt. public Bolt(int[] digits) { notches = new int[digits.length]; for (int i=0; i<SIZE; i++) notches[i] = digits[i]; } // Needed to access each digit of a Bolt. public int getDigit(int i) { return notches[i]; } // Made this work the opposite of the corresponding comparison. Surprisingly // it's not a circular definition, just a consistent one. public int compareTo(Nut n) { return -n.compareTo(this); } // Return a matching Nut. A matching nut is one who's number has each digit // be its complement. A complement to a digit is its difference from 9. public Nut getMatchingNut() { int[] tmp = new int[SIZE]; // We set each digit for the match. for (int i=0; i<SIZE; i++) tmp[i] = 9 - notches[i]; // Now create the object and return it. Nut match = new Nut(tmp); return match; } // For debugging purposes. /*public void print() { for (int i=0; i<SIZE; i++) System.out.print(notches[SIZE-1-i]); }*/ } class Nut { final private static int SIZE = 7; private int[] notches; // A Nut object is basically a seven digit number. public Nut(Random r) { notches = new int[SIZE]; for (int i=0; i<notches.length; i++) notches[i] = r.nextInt(10); } // A standard constructor given the information stored in a Nut. public Nut(int[] digits) { notches = new int[SIZE]; for (int i=0; i<SIZE; i++) notches[i] = digits[i]; } // Need this to access a single digit. public int getDigit(int i) { return notches[i]; } // Here we define a compareTo. public int compareTo(Bolt n) { int[] tmp = new int[SIZE]; int carry = 0; boolean low = false; // Add up the numbers stored in this and n. for (int i=0; i<SIZE; i++) { tmp[i] = (carry + notches[i] + n.getDigit(i))%10; carry = (carry + notches[i] + n.getDigit(i))/10; if (tmp[i] < 9) low = true; } // Our sum is a bunch of 9s, so we've got a match! if (tmp[SIZE-1] == 9 && !low) return 0; // Our sum is too big, so make this nut too big. else if (carry > 0) return 1; // Opposite case. else return -1; } // Works just like the mirror method in the Bolt class. public Bolt getMatchingBolt() { int[] tmp = new int[SIZE]; for (int i=0; i<7; i++) tmp[i] = 9 - notches[i]; return new Bolt(tmp); } // For debugging purposes. /*public void print() { for (int i=0; i<SIZE; i++) System.out.print(notches[SIZE-1-i]); }*/ } class NutsBolts { // Returns true iff each nut and each corresponding bolt in the two // respective arrays match eacy other. public static boolean correctFit(Nut[] nuts, Bolt[] bolts) { // Try out each corresponding nut and bolt. for (int i=0; i<nuts.length; i++) // See if these don't match. if (nuts[i].compareTo(bolts[i]) != 0) return false; // If we get here, they all matched. return true; } // Creates an array of Bolt objects with size number of elements utilizing // r. public static Bolt[] makeRandomBolts(Random r, int size) { // Allocate space for our bolts, Bolt[] tmp = new Bolt[size]; // Just create each object here and return the array. for (int i=0; i<size; i++) tmp[i] = new Bolt(r); return tmp; } // Creates an array of matching nuts to the array of bolts passed in. // It scrambles the nuts though, so that they are no longer in the correct // locations. public static Nut[] makeMatchingNuts(Random r, Bolt[] bolts) { // Create the array, and add in each matching nut. Nut[] tmp = new Nut[bolts.length]; for (int i=0; i<bolts.length; i++) { tmp[i] = bolts[i].getMatchingNut(); } // Here we mix the array of nuts up. for (int i=0; i<3*bolts.length; i++) { // Get two random indexes. int index1 = r.nextInt(bolts.length); int index2 = r.nextInt(bolts.length); // Swap them! Nut store = tmp[index1]; tmp[index1] = tmp[index2]; tmp[index2] = store; } // Return our array of mixed up, but matching nuts. return tmp; } } 仅处理属性 - 价值组合。在纯CSS中执行此操作的唯一方法是使用CSS hack定位支持@supports的浏览器。 (没有足够的浏览器支持::-webkit-scrollbar-thumb,因为它无论如何都有助于检查对@supports的支持。)

答案 1 :(得分:1)

您现在可以使用@supports selector()定位伪元素。这是您的用例的相关示例:

=SUMIFS(INDEX($C$3:$E$17,,MATCH(J$5,$C$2:$E$2,0)),$A$3:$A$17,$I6,$B$3:$B$17,">="&$J$1,$B$3:$B$17,"<="&$J$2)

请参阅this JSFiddle,它演示了浏览器对@supports selector(::-webkit-scrollbar-thumb) { .scroll-container { overflow: scroll } } 的支持

  1. Chrome 86
  2. Edge 87
  3. 歌剧72

但不是

  1. Firefox 82
  2. Safari 12

截至2020年12月,::-webkit-scrollbar-thumb的{​​{3}}约为72%。

答案 2 :(得分:0)

加上前面的答案,您可以编写伪选择器,如果浏览器不支持prop,它将跳过css声明。

例如:

li::marker{color:blue}

较旧的浏览器不会显示。

答案 3 :(得分:0)

这是我用来识别 Webkit 浏览器的。这是我能找到的最具体的伪选择器,其他引擎似乎(还)没有:

CSS.supports(`selector(input[type='time']::-webkit-calendar-picker-indicator)`)