1

I'm having trouble centering my Stripe Payment button on my landing page. I've tried margins, text-align and wrapped it in a div to no avail. I apologize, my css knowledge isn't great but I would appreciate the help!

    `<!-- Load Stripe.js on your website. -->
   <script src="https://js.stripe.com/v3"></script> <!-- Create a button that your 
 customers 
  click to complete their purchase. Customize the styling to suit your branding. -->
  <button style="background-color:#FF8800;color:#FFF; padding:8px 12px;border:0;border- 
 radius:4px;font-size:1.5em" id="checkout-button-plan_HBK7An1HxIpxXF" role="link">Start 
Free 
Trial</button>
<div id="error-message">
</div>
<script>
/* <![CDATA[ */
(function() {
 var stripe = Stripe('pk_live_tkRbcnwJtcbR40owQTnDC3E0');

  var checkoutButton = document.getElementById('checkout-button-plan_HBK7An1HxIpxXF');
  checkoutButton.addEventListener('click', function () {
// When the customer clicks on the button, redirect
// them to Checkout.
stripe.redirectToCheckout({
  items: [{plan: 'plan_HBK7An1HxIpxXF', quantity: 1}],

  // Do not rely on the redirect to the successUrl for fulfilling
  // purchases, customers may not always reach the success_url after
  // a successful payment.
  // Instead use one of the strategies described in
  // https://stripe.com/docs/payments/checkout/fulfillment
  successUrl: window.location.protocol + '//accountinguni.com/success',
  cancelUrl: window.location.protocol + '//accountinguni.com/canceled',
})
.then(function (result) {
  if (result.error) {
    // If `redirectToCheckout` fails due to a browser or network
    // error, display the localized error message to your customer.
    var displayError = document.getElementById('error-message');
    displayError.textContent = result.error.message;
    }
  });
 });
  })();
 /*]]>*/
 </script>`
  • Did you try `margin: 0px auto;` ? – EdgarAlexPoe Apr 29 '20 at 14:26
  • I don't agree with this question being a duplicate. The centering the Stripe Payment Request button I found pretty challenging as it is clearly set up to expand to the available space behind the scenes and aligning as I would normally resulted in the button collapsing. What worked for me: `margin-left: auto; margin-right: auto; text-align: center; width: 100%;` On a div that wrapped the button – James Mundy Jan 28 '21 at 17:25

2 Answers2

-1

Try inline styling

 <div style="text-align: center; width: 100%;"><button></button></div>
EdgarAlexPoe
  • 410
  • 3
  • 11
-1

You can easily use flex to put the elements in the center, both in width and height:

<div class="center">
    // Your Button
</div>

.center{
    display: flex;
    width: 100%;
    justify-content: center;
}
Mohsen007
  • 285
  • 3
  • 13
  • Thank you but that did not work. I placed the div around the button but the code starting with .center just displays as text. Any suggestions? – Nathan Garrett Apr 29 '20 at 15:06