【问题标题】:Center Align a Stripe Payment Button [duplicate]中心对齐条纹支付按钮[重复]
【发布时间】:2020-08-13 16:20:14
【问题描述】:

我无法将 Stripe Payment 按钮置于着陆页的中心。我尝试了边距,文本对齐并将其包装在 div 中无济于事。很抱歉,我的 css 知识不是很好,但我会很感激你的帮助!

    `<!-- 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>`

【问题讨论】:

  • 你试过margin: 0px auto; 吗?
  • 我不同意这个问题是重复的。我发现将 Stripe Payment Request 按钮居中非常具有挑战性,因为它显然设置为扩展到幕后的可用空间并对齐,因为我通常会导致按钮折叠。什么对我有用:margin-left: auto; margin-right: auto; text-align: center; width: 100%; 在包装按钮的 div 上

标签: css center


【解决方案1】:

尝试内联样式

 <div style="text-align: center; width: 100%;"><button></button></div>

【讨论】:

  • 谢谢,但我还是有问题。我查看了您的 jsfiddle,我可以看到 HTML 代码和 CSS 代码是并排的。如何将该 css 代码注入 HTML?我像你一样在整个代码周围放置了 div 类,但 css 代码一直显示为纯文本。
  • 创建一个单独的 css 文件,例如 style.css。将该文件添加到您的 html 文件所在的根目录中。在 中添加&lt;link rel="stylesheet" href="style.css"&gt;。这会将您的 css 添加到 html 文件中。
  • 我正在使用一个名为 Jimdo 的免费登录页面构建器。我不相信我可以访问根目录。那有办法解决吗?如果你想看看,我可以给你登录。我只是将此按钮代码添加到登录页面构建器上的 html 小部件中。
  • 在这种情况下,只需将您的样式添加到您的 html 上方 &lt;style&gt;.center {width: 100%; text-align: center;}&lt;/style&gt;
【解决方案2】:

您可以轻松地使用 flex 将元素放在中心,无论是宽度还是高度:

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

.center{
    display: flex;
    width: 100%;
    justify-content: center;
}

【讨论】:

  • 谢谢,但没有奏效。我将 div 放在按钮周围,但以 .center 开头的代码仅显示为文本。有什么建议吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-20
  • 2017-07-03
  • 2017-09-14
  • 2013-11-15
  • 2016-08-08
  • 2019-07-04
相关资源
最近更新 更多