StripeElements不会样式

reactjs React.js

阳光前端

2020-03-24

我有如下所示的Stripe表单,可以很好地加载

  render() {
    const createOptions = (fontSize: string) => {
      return {
        style: {
          base: {
            fontSize,
            color: '#424770',
            letterSpacing: '0.025em',
            fontFamily: 'Source Code Pro, monospace',
            '::placeholder': {
              color: '#aab7c4',
            },
          },
          invalid: {
            color: '#9e2146',
          },
        },
      };
    };

    return (
      <div className={styles.cardsection}>
        <form onSubmit={this.handleSubmit}>
        <label>
        Card Details
            <CardElement {...createOptions(this.props.fontSize)} />
          </label>
          <button>
            {this.state.paid === 'waiting' ? 'Please wait...' : 'Confirm order'}
          </button>
        </form>
      </div>
    );
  }
}

export default injectStripe(CheckoutForm);

我有我的styles.less文件:

.cardsection {
  width: 60%;
  margin: auto;
  margin-top: 30px;
  background-color: #f6f9fc;
  padding: 20px;

  label {
    color: #6b7c93;
    font-weight: 300;
    letter-spacing: 0.025em;

    .StripeElement {
      display: block;
      margin: 10px 0 20px 0;
      max-width: 500px;
      padding: 10px 14px;
      box-shadow: rgba(50, 50, 93, 0.14902) 0px 1px 3px, rgba(0, 0, 0, 0.0196078) 0px 1px 0px;
      border-radius: 4px;
      background: white;
    }

    .StripeElement--focus {
      box-shadow: rgba(50, 50, 93, 0.109804) 0px 4px 6px, rgba(0, 0, 0, 0.0784314) 0px 1px 3px;
      -webkit-transition: all 150ms ease;
      transition: all 150ms ease;
    }
  }
}

button {
  white-space: nowrap;
  border: 0;
  outline: 0;
  display: inline-block;
  height: 40px;
  line-height: 40px;
  padding: 0 14px;
  box-shadow: 0 4px 6px rgba(50, 50, 93, .11), 0 1px 3px rgba(0, 0, 0, .08);
  color: #fff;
  border-radius: 4px;
  font-size: 15px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.025em;
  background-color: #6772e5;
  text-decoration: none;
  -webkit-transition: all 150ms ease;
  transition: all 150ms ease;
  margin-top: 10px;
}

button:hover {
  color: #fff;
  cursor: pointer;
  background-color: #7795f8;
  transform: translateY(-1px);
  box-shadow: 0 7px 14px rgba(50, 50, 93, .10), 0 3px 6px rgba(0, 0, 0, .08);
}

由于某些原因,我无法设置StripeElements的样式。我所有其他样式都可以,但Stripe Elements却不能。我已经检查了加载的HTML,在标签内是我的div,名为StripeElement

从下面可以看到,输入框未设置样式。 在此处输入图片说明

我正在使用React-Stripe-Element库,并使用Next.js在SSR应用程序中实现它

编辑:我已经找到了问题,但我不确定如何克服它。构建我的应用程序时,在CSS和html中为我的类分配了一个随机变量。

例如,cardsection变为cardsection__Xy12xg2。问题是在我的HTML中,StripeElement保持为StripeElement,但我的CSS变成StripeElement__28vnshY

任何想法如何克服这个?

第3300篇《StripeElements不会样式》来自Winter(https://github.com/aiyld/aiyld.github.io)的站点

0个回答

问题类别

JavaScript Ckeditor Python Webpack TypeScript Vue.js React.js ExpressJS KoaJS CSS Node.js HTML Django 单元测试 PHP Asp.net jQuery Bootstrap IOS Android