I’m trying some experiments with CSS vars, and I couldn’t get this to work or find any documentation about it. Does anyone know if it’s possible to use a CSS var in a CSS3 selector?
I made the following example to explain what I’m trying to do. This example is Chrome only.
JSFIDDLE
http://jsfiddle.net/68Rrn/
CSS
:root {
-webkit-var-count: 5; /* define my var! */
}
li {
width:100px;
height:100px;
background-color:blue;
display:inline-block;
list-style:none;
}
ul li:nth-child(4) {
background-color:red;
}
ul li:nth-child(-webkit-var(count)) { /* I can't get this working, is it even supported? I'm trying to target the 5th element with my var. */
background-color:black;
}
HTML
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…