使用ID设置背景颜色

时间:2018-02-08 05:11:39

标签: html css svg background-color

我的网页上有多个图表,我想将一个特定图表的背景颜色更改为白色,为此我使用了以下css样式。

svg g:first-of-type rect {
  fill-opacity: 0;
}
svg g:first-of-type path {
  stroke: #e6e6e6;
}
svg g:first-of-type rect:not(:last-child) {
  fill: #ffffff;
}

使用上面的代码,它使我的应用程序中的所有图表颜色变为白色,我如何将其应用于特定图表。我尝试在svg元素前使用div id值,同时声明样式但是不工作..

4 个答案:

答案 0 :(得分:1)

将id用于父div。 希望这会有所帮助。



<style>
/*   want to make the grey color shown in chart2 to white*/
  /*  svg g:first-of-type rect {
        fill-opacity: 0;
    }
    svg g:first-of-type path {
        stroke: #e6e6e6;
    }
    svg g:first-of-type rect:not(:last-child) {
        fill: #ffffff;
    }*/
    #chartTwo{
      background-color:Red;
    }
    
</style> 

</head>

<body>
  <div ng-controller="myController">
    <div id="chartOne" google-chart chart="myChart"></div>
  </div>
  
  <br>
   <div ng-controller="myController2"  id="chartTwo">
    <div  google-chart chart="myChart"></div>
  </div>
  
</body>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

正如你的傻瓜说你在两个图表上使用不同的ids那么为什么不使用那个特定的图表id来应用css,如

backgroundColornonetransparent无法在svg中使用,因为颜色来自svg fill属性。

#chartTwo svg g:first-of-type rect {
  fill-opacity: 0;
}

#chartTwo svg g:first-of-type path {
  stroke: #e6e6e6;
}

#chartTwo svg g:first-of-type rect:not(:last-child) {
  fill: #ffffff;
}

<强> Updated Plunker

答案 2 :(得分:0)

在CSS中试用

background-color: none !important;

background-color: transparent !important;

使用!important它会起作用..

答案 3 :(得分:-2)

import re
with open(path, 'r') as f:
    result = re.sub(r'(^ | $)', '', re.sub(r'\w+', ' ', f.read()))
    print(result)
CSS中的

<body>
  <div ng-controller="myController">
    <div id="chartOne" google-chart chart="myChart"></div>
  </div>

  <br>
   <div ng-controller="myController2" class="scnd">
    <div id="chartTwo" google-chart chart="myChart"></div>
  </div>

</body>

你写的样式不正确

.scnd
{
    /*Your style here*/
}
相关问题