Strange "initial" values in d3.js

background, css, d3.js, javascript, styles

Solution

This has nothing to do with D3, but with the implicit nature of CSS. When you specify the CSS background property, you are actually specifying multiple properties in shorthand. For example,

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

Is actually shorthand for

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

So, when you set the style "background", your browser automatically expands this shorthand to the full form. That's why you see all of these additional styles; they represent the computed values.

Problem

By executing code that is similar to this (`d3.select(..).append("div")`), I get `div`s with such style properties: ``` <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> ``` Questions: - a) Where does `initial` comes from? b) Is it possible to redefine "defaults"? - Is it Ok that d3 litters in the properties with unnecessary values? - Chrome says that `background-position: initial initial;` and `background-repeat: initial initial;` are `Invalid property value`s. Is it a bug of d3? How can we deal with this error?

Original source