I am looking for a way to customise the layout of 'card number' 'expiry date' and 'CCV' fields when using Stripe Elements and injecting these fields through card.mount('#card-element');
as described in the first example of this page https://stripe.com/docs/stripe-js
It puts all the card fields in one row, I want to change that layout and put them in different rows.
Any ideas?
Thanks in advance
In addition to themes , variables and rules , we have provided additional appearance configuration options to style Elements. You can customize these by adding them to the appearance object: const appearance = { labels: 'floating', // other configurations such as `theme`, `variables` and `rules`... }
Stripe Elements is a set of prebuilt UI components for building your web checkout flow. It's available as a feature of Stripe. js, our foundational JavaScript library for building payment flows. Stripe. js tokenizes sensitive payment details within an Element without ever having them touch your server.
Stripe works with card networks and automatically attempts to update saved card details whenever a customer receives a new card (for example, replacing an expired card or one that was reported lost or stolen).
The element is an iframe, which is another window, which has its own window object and document object. The parent page cannot access these objects, unless the iframe is in the same origin.
You can do this by creating a separate div for each card input (number, expiry, CVC), which you can layout however you like:
<div id="example3-card-number"></div>
<div id="example3-card-expiry"></div>
<div id="example3-card-cvc"></div>
Then tell Stripe Elements about each one:
var cardNumber = elements.create('cardNumber');
cardNumber.mount('#example3-card-number');
var cardExpiry = elements.create('cardExpiry');
cardExpiry.mount('#example3-card-expiry');
var cardCvc = elements.create('cardCvc');
cardCvc.mount('#example3-card-cvc');
Ref: https://stripe.dev/elements-examples/ (Example 3)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With