【发布时间】:2013-12-27 17:56:38
【问题描述】:
我想知道我是否可以将 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));
}
draft 说它应该可以工作,但在我的情况下(Chrome 31.0.1650.63 m 和 Firefox 25.0.1)它没有。那么有两种情况:
- 我做错了
- 尚不支持
怎么了?
【问题讨论】: