::before伪元素的CSS代码中,我希望根据在Reaction组件中 Select 的 colored颜色 动态更改框阴影 colored颜色 .

react 部分

 <>
      <div className="card">
        <div className="percent">
          <div
            className="dot"
            style={{
              transform: `rotate(${3.6 * off}deg)`,
            }}
          ></div>
          <svg>
            <circle cx={70} cy={70} r={70}></circle>
            <circle
              cx={70}
              cy={70}
              r={70}
              style={{
                stroke: colors,
                strokeDasharray: 440,
                strokeDashoffset: 440 - (440 * off) / 100,
              }}
            ></circle>
          </svg>
        </div>
      </div>
    </>

Css部件

.dot {
  position: absolute;
  inset: 5px;
  z-index: 10;
  animation: anmationdot 2s linear forwards;
}
@keyframes anmationdot {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(calc(3.6 * 85));
  }
}
.dot::before {
  content: "";
  position: absolute;
  top: -5px;
  left: 50%;
  transform: translateX(-50%);
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: aqua;
  box-shadow: 0 0 10px aqua, 0 0 30px aqua;
}

我在try 使用样式并将其作为根元素从Reaction发送时遇到错误.

推荐答案

您需要创建一种解决方法.使用css变量是实现目标的适当 Select .

  1. 将 colored颜色 值设置为根元素或伪元素的父元素上的css变量.
  2. 您必须在::before伪元素的Desired属性中使用此css变量.

下面是一个示例解决方案:

React Code:

<>
  <div className="card">
    <div className="percent" style={{ "--dot-shadow-color": colors }}>
      <div
        className="dot"
        style={{
          transform: `rotate(${3.6 * off}deg)`,
        }}
      ></div>
      <svg>
        <circle cx={70} cy={70} r={70}></circle>
        <circle
          cx={70}
          cy={70}
          r={70}
          style={{
            stroke: colors,
            strokeDasharray: 440,
            strokeDashoffset: 440 - (440 * off) / 100,
          }}
        ></circle>
      </svg>
    </div>
  </div>
</>

CSS Code:

.dot {
  position: absolute;
  inset: 5px;
  z-index: 10;
  animation: anmationdot 2s linear forwards;
}
@keyframes anmationdot {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(calc(3.6 * 85));
  }
}
.dot::before {
  content: "";
  position: absolute;
  top: -5px;
  left: 50%;
  transform: translateX(-50%);
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: var(--dot-shadow-color, aqua); /* Fallback to 'aqua' if not provided */
  box-shadow: 0 0 10px var(--dot-shadow-color, aqua), 0 0 30px var(--dot-shadow-color, aqua);
}

在这种排列中,.dot类中::before个伪元素的框阴影的 colored颜色 将根据Reaction组件中的colors变量中指定的 colored颜色 进行调整和移动.

Css相关问答推荐

在react native中应用阴影

如何防止css边框缩小div?

将特定样式应用于递归Angular 元素

尽管 URL 路径正确,但背景图像未显示

覆盖现有像素的混合

基于高度的容器查询不起作用

使用框架时样式冲突导致的 CSS 网格布局问题

如何在启动时滚动 div 的底部?

在 css Select 器中匹配 unicode char

如何在特定元素之前 Select 每个元素

BootStrap:右对齐嵌套手风琴

是否可以删除悬停在链接上时出现的手形光标? (或将其设置为普通指针)

使用 Twitter Bootstrap 使页脚粘在页面底部

如何在 html/css 中的图像旁边垂直居中文本?

如何动态生成用逗号分隔的类列表?

Highcharts 图表选项 backgroundColor:'transparent' 在 IE 8 上显示黑色

谷歌浏览器两种元素样式的区别

如何更改 HTML 输入标签的字体和字体大小?

为什么浏览器会为 CSS 属性创建供应商前缀?

CSS(webkit):在绝对定位元素上用底部覆盖顶部