修改“Pay with Card”条纹按钮的样式

时间:2016-04-16 02:20:54

标签: css stripe-payments

是否可以修改“Pay with Card”条纹按钮的样式?我试过修改,

  • 添加在外部样式表中定义的新类
  • 在外部样式表中修改自己的stripe-button
  • 并使用style=""
  • 进行内联编辑

但是我无法通过按钮来改变它的风格。

看起来有可能使用custom integration代替simple integration(来源:https://stripe.com/docs/checkout#integration-simple),但我希望有更简单的东西。

具有默认样式的按钮:

enter image description here

有没有人有这方面的经验?

(如果有任何不同,我将整合到Ruby on Rails中。)

10 个答案:

答案 0 :(得分:35)

这些都不适合我。我最终在javascript中隐藏了按钮并创建了一个新按钮。

<form action="/your-server-side-code" method="POST">
    <script src="https://checkout.stripe.com/checkout.js" class="stripe-button"
        data-key="xxx"
        data-amount="999"
        data-name="zzz"         
        data-locale="auto">
    </script>
    <script>
        // Hide default stripe button, be careful there if you
        // have more than 1 button of that class
        document.getElementsByClassName("stripe-button-el")[0].style.display = 'none';
    </script>
    <button type="submit" class="yourCustomClass">Buy my things</button>
</form>

答案 1 :(得分:12)

搜索此

.stripe-button-el span

我认为这是您必须修改自己的按钮样式的地方。 您可以在自己的外部css文件中覆盖它。

答案 2 :(得分:9)

虽然有点hacky,但对于任何想要使用不同按钮以及简单集成的超快速简单方法的人来说,尤其是如果你没有“坚实的JavaScript”技巧&#34;,您只需隐藏条纹按钮;

.stripe-button-el { display: none }

这样,表单中的任何提交按钮都会调用结帐,因此您可以在引入Stripe之前使用已有的按钮。

答案 3 :(得分:6)

以下内容将使用自定义颜色#EB649C覆盖背景颜色。需要禁用背景图像,以及设置按钮及其内部标记内的样式。

button.stripe-button-el,
button.stripe-button-el>span {
  background-color: #EB649C !important;
  background-image: none;
}

答案 4 :(得分:2)

您可以使用Jquery删除按钮样式并添加自己的样式。为我带来了魅力:

<script type="text/javascript">
    $(document).ready(function(){
        $(".stripe-button-el span").remove();
            $("button.stripe-button-el").removeAttr('style').css({
                "display":"inline-block",
                "width":"100%",
                "padding":"15px",
                "background":"#3fb0ac",
                "color":"white",
                "font-size":"1.3em" }).html("Sign Me Up!");
        });
</script>

答案 5 :(得分:2)

使用jQuery,你也可以像这样简单地缩放按钮:

<script>
  $(function() {
    $(".stripe-button-el").css({'transform': 'scale(2)'});
  });
</script>

或者用带有您想要的任何图像的按钮替换它,如下所示:

<script>
  $(function() {
    $(".stripe-button-el").replaceWith('<button type="submit" class="pay"><img src="/assets/paywithcard.jpg"></button>');
  });
</script>

答案 6 :(得分:1)

您应使用数据标签作为常规条纹Checkout API的一部分:

<script
  src="https://checkout.stripe.com/checkout.js" class="stripe-button"
  data-key="<%= ENV.fetch('STRIPE_PUBLISHABLE_KEY') %>"
  data-amount="10000"
  data-label="Proceed to Pay with Card"
  ...
  ...
  data-locale="auto">
  </script>

答案 7 :(得分:0)

.stripe-button-el跨度实际上有效。

但是您需要在CSS中添加!important才能覆盖默认CSS。

答案 8 :(得分:0)

您可以尝试一下,

$(".stripe-button-el").find("span").remove();
$(".stripe-button-el").html("Proceed to pay");

用卡付款在跨度之内。

答案 9 :(得分:0)

对于那些想要更改按钮背景色的人,请确保您执行

之类的操作
.stripe-button-el span {
  background: #5e366a !important;
  background-image:none !important;
  background-color: #5e366a !important;
}

在您的CSS文件中。这将更改按钮的实际背景。如果希望更改父div,则可以在不使用span的情况下执行相同的操作,也可以执行直接的内联样式。

相关问题