我在css中有这个(代码行108):

.domain {
    fill: 'none';
    stroke-width: 0.7;
    stroke: 'black';
}

.tick {
    fill: 'none';
    stroke-width: 0.7;
    stroke: 'black';
}


而这在javascript中(代码行358):

// Add y axis with ticks and tick markers
var axisPadding = 2;
var leftAxisGroup = svg
    .append('g')
    .attr({
        transform: 'translate(' + (margin.left - axisPadding) + ',' + (margin.top) + ')',
        id: "yAxisG"
    });
var axisY = d3.svg.axis()
    .orient('left')
    .scale(yScale);
leftAxisGroup.call(axisY);


为什么不应用样式?如何确保已应用?

完整的脚本和上下文在这里:https://plnkr.co/edit/aSgNLb?p=preview

最佳答案

上面的CSS可以更改为

selector {
    fill: none; /* no quotes */
    stroke: black;  /* no quotes */
}




关键字值是标识符,必须按原样使用而不使用引号。当放在引号内时,它们会变成字符串,这些字符串在其属性的值定义下没有任何意义。因此,UA /浏览器未将其解析为有效。

CSS规格:
Textual Valuesstrings


  标识符不能被引用;否则,它们将被解释为字符串。


脚注:SVG的填充和描边属性:https://www.w3.org/TR/SVG/painting.html#SpecifyingPaint

10-05 20:33
查看更多