【问题标题】:How to change Steps Color in ( Ant-design )如何更改步骤颜色(Ant-design)
【发布时间】:2019-04-26 01:14:17
【问题描述】:

我是 Ant 设计的新手。目前我正在研究 ReactJs 项目,我在我的项目中使用了Steps。我想改变Steps 的颜色,但不知道怎么可能。我将分享 ant-design (Steps) 代码。请帮帮我
谢谢

您可能会在this codesandbox 中看到Steps 的示例

代码

import React from 'react';
import ReactDOM from 'react-dom';
import 'antd/dist/antd.css';
import './index.css';
import { Steps, Button, message } from 'antd';

const Step = Steps.Step;

const steps = [{
  title: 'First',
  content: 'First-content',
}, {
  title: 'Second',
  content: 'Second-content',
}, {
  title: 'Last',
  content: 'Last-content',
}];

class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      current: 0,
    };
  }

  next() {
    const current = this.state.current + 1;
    this.setState({ current });
  }

  prev() {
    const current = this.state.current - 1;
    this.setState({ current });
  }

  render() {
    const { current } = this.state;
    return (
      <div>
        <Steps current={current}>
          {steps.map(item => <Step key={item.title} title={item.title} />)}
        </Steps>
        <div className="steps-content">{steps[current].content}</div>
        <div className="steps-action">
          {
            current < steps.length - 1
            && <Button type="primary" onClick={() => this.next()}>Next</Button>
          }
          {
            current === steps.length - 1
            && <Button type="primary" onClick={() => message.success('Processing complete!')}>Done</Button>
          }
          {
            current > 0
            && (
            <Button style={{ marginLeft: 8 }} onClick={() => this.prev()}>
              Previous
            </Button>
            )
          }
        </div>
      </div>
    );
  }
}

ReactDOM.render(<App />, document.getElementById('container'));

【问题讨论】:

标签: javascript reactjs react-native ant-design-pro


【解决方案1】:

使用内联样式

代码

import React from "react";
import ReactDOM from "react-dom";
import "antd/dist/antd.css";
import "./index.css";
import { Steps, Button, message } from "antd";

const Step = Steps.Step;

const steps = [
  {
    title: "First",
    content: "First-content"
  },
  {
    title: "Second",
    content: "Second-content"
  },
  {
    title: "Last",
    content: "Last-content"
  }
];

class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      current: 0
    };
  }

  next() {
    const current = this.state.current + 1;
    this.setState({ current });
  }

  prev() {
    const current = this.state.current - 1;
    this.setState({ current });
  }

  render() {
    const { current } = this.state;
    return (
      <div>
        <Steps current={current} style={{ "background-color": "blueviolet" }}>
          {steps.map(item => (
            <Step key={item.title} title={item.title} />
          ))}
        </Steps>
        <div className="steps-content" style={{ "background-color": "grey" }}>
          {steps[current].content}
        </div>
        <div className="steps-action" style={{ "background-color": "blue" }}>
          {current < steps.length - 1 && (
            <Button
              type="primary"
              style={{ "background-color": "red" }}
              onClick={() => this.next()}
            >
              Next
            </Button>
          )}
          {current === steps.length - 1 && (
            <Button
              type="primary"
              onClick={() => message.success("Processing complete!")}
            >
              Done
            </Button>
          )}
          {current > 0 && (
            <Button style={{ marginLeft: 8 }} onClick={() => this.prev()}>
              Previous
            </Button>
          )}
        </div>
      </div>
    );
  }
}

ReactDOM.render(<App />, document.getElementById("container"));

【讨论】:

  • 感谢您的回复,但我想更改(1 ,2 ,3 ,4 )等步骤的颜色,因为您看到它们使用默认颜色(蓝色)
【解决方案2】:

尝试添加以下 CSS

.ant-steps-item-process .ant-steps-item-icon { background: red; }

在这个example中看到index.css

顺便说一下,你有一个更健壮的方法来改变 ant 框架样式,请参考documenatation

【讨论】:

  • 当你改变步的尾部颜色时使用这种样式
【解决方案3】:

如果您更改所有步尾颜色,那么 将以下样式放入 index.css

.ant-steps-item-finish
  > .ant-steps-item-container
  > .ant-steps-item-tail::after {
  background-color: red !important;
}

改变背景色 如果您只更改一步尾部颜色,然后像这样将 className 放入Step

       <Steps className="custome-step" current={1} progressDot>
              <Step title="In Progress" description="Loan Application" />
              <Step title="" description="Loan Vetting" />
              <Step title="" description="Disbursement" />
       </Steps>

index.css

.custome-step .ant-steps-item-finish > .ant-steps-item-container > .ant-steps-item-tail::after {
  background-color: red !important;
}

example

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-16
    • 2020-08-28
    • 2021-03-05
    • 2021-06-30
    • 1970-01-01
    • 2021-02-25
    • 2020-11-12
    • 2020-11-02
    相关资源
    最近更新 更多