How can I put border styling with react-stripe-ele

2020-08-09 09:19发布

About this React component library.

How can I put border styling with input component?

<CardElement style={{
  base: {
    fontSize: '18px',
    border: '1px solid red' // it is not work.
  } 
}} />

but, seems they didn't provide custom style interface, though.

Anyone know?

Update:

following are sample code that using StripeElement class to apply custom styling.

.StripeElement {
  border: 1px solid #eee;
}

.StripeElement--invalid {
  border: 1px solid red;
}

3条回答
Lonely孤独者°
2楼-- · 2020-08-09 09:21

Great question! As noted here, to apply padding or a border to a Stripe element you want to style the parent DOM node that contains the element, not the element itself:

https://stripe.com/docs/elements/reference#the-element-container

I'd wrap your CardElement in a div and then apply styling to that. As noted above, Elements automatically applies the StripeElement class to the parent element, as well as complete/empty/focus/invalid states.

查看更多
够拽才男人
3楼-- · 2020-08-09 09:38

The simplest solution is:

<div
  style={
    {
     border: '2px solid red'
    }
  }
>
</div>
查看更多
贪生不怕死
4楼-- · 2020-08-09 09:45

I was trying to add padding, and the wrapper div did not work for me. However, they added a change to react-stripe-elements to allow for a className on the card element. That worked for me:

In my css:

.card-element {
  padding: 11.4px 12px;
}

For my CardElement:

<CardElement style={style} className="card-element" />

You still have to use inline styling for the attributes that are in the element options styles: https://stripe.com/docs/stripe-js/reference#element-options

查看更多
登录 后发表回答