css - 将 Lighten Css 特性嵌入到 Jsx/React

标签 css reactjs jsx

我目前使用以下语法将状态颜色嵌入 jsx。

 <div className="preview-box" style={{backgroundColor:this.state.color}}>

有没有办法使用 css 中的亮化功能来做这样的事情?

 <div className="preview-box" style={{backgroundColor: lighten(this.state.color, 15%)}}>

最佳答案

您可以使用SCSS 获取backgroundColor: lighten(this.state.color, 15%)

CSS 部分

$awesome-blue: #2196F3;
$width: 100%;
$height: 500px;

    .box {
      background: lighten($awesome-blue, 10%); /* As your need */
      width: $width;
      height:$height;
      display:flex;
      align-items:center;
      justify-content:center;
    }

我只是发布了一个例子来说明它是如何工作的,它可能会对你有所帮助

Working fiddle with scss

关于css - 将 Lighten Css 特性嵌入到 Jsx/React,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44512011/

相关文章:

html - 无法让这些 div 内联显示

css - 如果 'nowrap' 的 flexbox 容器溢出,为什么移动视口(viewport)尺寸会发生变化?

html - CSS 盒模型 Chrome 边框颜色

javascript - 使用react js和orientationchange事件时如何检测移动网站中的屏幕方向?

javascript - 根据对象属性获取单独的列表

html - 将小图像放在背景颜色 html 上?

javascript - react 显示未正确更新

javascript - React - 你可以变异修改 this.props.children 来动态(以编程方式)添加子组件

javascript - 动态地向 React map 函数中的前 n 个元素添加一个类

javascript - 在 React JS 中重置状态