d3.js中的奇怪“初始”值

时间:2012-05-15 06:59:09

标签: javascript css background styles d3.js

通过执行类似于thisd3.select(..).append("div"))的代码,我得到具有此类样式属性的div

<div id="id6" 
  style="
    background-image: initial; 
    background-attachment: initial; 
    background-origin: initial; 
    background-clip: initial; 
    background-color: rgb(255, 255, 255); 
    background-position: initial initial; 
    background-repeat: initial initial; ">
5
</div>

问题:

  1. a)initial来自哪里? b)是否可以重新定义“默认值”?
  2. d3在unnecessary values
  3. 的属性中是否有问题
  4. Chrome说background-position: initial initial;和         background-repeat: initial initial;Invalid property value。这是d3的错误吗?我们如何处理这个错误?

1 个答案:

答案 0 :(得分:5)

这与D3无关,但具有CSS的隐含性质。指定CSS background property时,实际上是以速记方式指定多个属性。例如,

background: url(chess.png) gray 50% repeat fixed;

实际上是

的简写
background-image: url(chess.png);
background-color: gray;
background-position: 50% 50%;
background-repeat: repeat;
background-attachment: fixed;

因此,当您设置样式“背景”时,您的浏览器会自动将此简写扩展为完整表单。这就是为什么你会看到所有这些额外的风格;它们代表computed values