I cannot understand how the CSS padding property for svg elements is interpreted. The following snippet ( jsFiddle ):
<!DOCTYPE html> <meta charset="utf-8"> <title>noob d3</title> <style> svg{background-color:beige; padding:0px 0px 50px 50px;} rect{fill:red; stroke:none; shape-rendering:crispEdges;} </style> <body> <script src="//d3js.org/d3.v3.min.js"></script> <script> d3.select("body") .append("svg") .attr("width", 155) .attr("height", 105) .append("g") .append("rect") .attr("class", "frame") .attr("x", 50) .attr("y", 50) .attr("width", 50) .attr("height", 50); </script> </body>
... is significantly different in Firefox and Chrome. To make matters worse, not a single display makes sense to me: the size of the displayed svg element (the "beige" rectangle) looks much larger than I expected.
So my question is twofold: 1) How should the padding property of an svg element affect where things are drawn in it? 2) Is there a polyfill that ensures that both the Chrome and Firefox browsers handle the padding the same way?
kjo
source share