【发布时间】:2021-03-29 06:31:25
【问题描述】:
我使用了一个图表库。我想定位和修改该库使用外部 CSS 生成的 CSS 类的属性。我们假设检查器中的代码是这样的-
<div id="apexcharts9xagqubx" class="apexcharts-canvas apexcharts9xagqubx apexcharts-theme-light" style="width: 319.5px; height: 200px;">
<svg id="SvgjsSvg1001" width="319.5" height="200" xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svgjs="http://svgjs.dev/svgjs" class="apexcharts-svg apexcharts-zoomable hovering-zoom">
<div>
顶点图表文档说我可以定位.apexcharts-canvas 并更改背景颜色。我已经这样做了:
import React from "react";
import ReactApexChart from 'react-apexcharts'
import './apex.module.css'
return (
<div id="chart">
<ReactApexChart options={data.options} series={data.series} type="area" height={200}/>
</div>
);
在apex.module.css 里面我是这样做的:
.apexcharts-canvas{
background-color: black;
}
现在呢?
好像不行。
【问题讨论】:
-
您可以通过在自己的 CSS 文件中创建自定义 CSS 类,在必要时使用
!important标志,并使用组件的className属性应用它来绕过它。 -
@mattbbc 如何在该组件内高度嵌套的 div 中实现自定义 css 类?
-
您是否在使用 CSS 模块或类似的系统来处理类名,以便它们不会在组件之间发生冲突?如果是这样,您的
.apexcharts-canvas将被编译成类似.apexcharts-canvas-gE35CF的内容,您需要在 CSS 文件中添加更多内容来告诉它不要这样做。 -
您可以尝试将
!important标志添加到您已实现的background-color值。
标签: css reactjs react-component