我想知道我是否可以将 calc() 函数与 attr() 函数结合起来以实现类似以下的效果:
<div class="content" data-x="1">
This box should have a width of 100px
</div>
<div class="content" data-x="2">
This box should have a width of 200px
</div>
<div class="content" data-x="3">
This box should have a width of 300px
</div>
CSS
.content{
//Fallback. If no calc is supported, just leave it at 100px
width: 100px;
}
.content[data-x]{
// Multiply the width of the element by the factor of data-x
width: calc(100px * attr(data-x));
}
草案说它应该工作,但在我的情况下(Chrome 31.0.1650.63 m 和 Firefox 25.0.1)它没有。那么有两种情况:
- 我做错了
- 尚不支持
这是怎么回事?