"Complications arising from the clash between Stripe components and Bootstrap 4.1 styles

Is there a conflict between Bootstrap 4.1 and Stripe's elements API? I've searched for a solution but couldn't find any confirmation.

Below is the source code to replicate this issue, along with live examples using fiddles. Has anyone encountered this before or knows of a fix?

Fiddle without including bootstrap 4.1

Fiddle WITH bootstrap 4.1

<html>
<head>
    <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
    <script src="https://js.stripe.com/v3/"></script>

    <!-- When below three lines are included, stripe elements are incorrectly rendered -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>


    <script>
        $(document).ready(function(){

            var stripe = Stripe($('#spk').val());
            var elements = stripe.elements();

            var style = {
                base: {
                    // Add your base input styles here. For example:
                    fontSize: '16px',
                    lineHeight: '24px'
                }
            };

            var card = elements.create('card', {style: style});
            card.mount('#card-element');
            card.addEventListener('change', function(event) {
                var displayError = document.getElementById('card-errors');
                if (event.error) {
                    displayError.textContent = event.error.message;
                } else {
                    displayError.textContent = '';
                }
            });

            var form = document.getElementById('paymentMethodForm');
            form.addEventListener('submit', function(event) {
                event.preventDefault();
                stripe.createToken(card).then(function(result) {
                    if (result.error) {
                        var errorElement = document.getElementById('card-errors');
                        errorElement.textContent = result.error.message;
                    } else {
                        stripeTokenHandler(result.token);
                    }
                });
            });

            function stripeTokenHandler(token) {
                var form = document.getElementById('paymentMethodForm');
                var hiddenInput = document.createElement('input');
                hiddenInput.setAttribute('type', 'hidden');
                hiddenInput.setAttribute('name', 'stripeToken');
                hiddenInput.setAttribute('value', token.id);
                form.appendChild(hiddenInput);
                form.submit();
            }

        });
    </script>

</head>
<body>

<div style="width:400px;">
    <!-- sample test key from stripe website -->
    <input type="hidden" id="spk" value="pk_test_TYooMQauvdEDq54NiTphI7jx"/>
    <form action="/" method="POST" id="paymentMethodForm" class="d-block">
        <div class="form-row">
            <label for="card-element">Credit or debit card</label>
            <div id="card-element" style="">
            </div>
            <div class="alert-danger text-center" id="card-errors" role="alert"></div>
        </div>
        <div class="text-center">
            <br/>
            <button class="btn btn-primary">Add Payment Method</button>
        </div>
    </form>
</div>


</body>
</html>

Answer №1

Here's the solution using CSS:

.input-section {
    display: inline-block;
}

Currently, Bootstrap is utilizing display: flex.

Take a look at this example.

Answer №2

Avoid using the form-row class as Bootstrap applies different styling to it compared to what Stripe anticipates. Consider renaming it to something else. Modifying the style, as facechomp recommended, may cause other complications when Bootstrap relies on display: flex.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The overflowing issue with the Nextjs Tailwind Marquee Component is causing a display

I've recently developed a unique nextjs/tailwind component. This component displays an isometric marquee that scrolls horizontally. However, I'm facing an issue where the content overflows to the right and causes the page to become horizontally s ...

What are some tips for utilizing CSS sprites with finesse within an inline element?

Although I am familiar with this workaround for the inline-block property due to poor browser support, I am curious if there is a more sophisticated solution for using CSS sprites without the need for block elements to have line breaks. For example, in th ...

When the mouse hovers, the background image of <ul> <li> tabs will disappear

I have a simple set of HTML tabs using <ul> and <li> elements with some custom CSS styles. You can view the code on jsfiddle here. Each tab follows this structure (for more details, please refer to the linked code): ... <li class="icon ...

What could be causing my Bootstrap accordion to malfunction?

Currently, I am in the process of constructing a website using Bootstrap 4. I have incorporated 3 individual <div> elements, each containing an accordion. These <div> sections are assigned their own unique id to facilitate the showing and hidin ...

How can I customize the connector for Ant Design Steps?

Does anyone know how to adjust the color and width of the connector line in Ant Design's Steps component? I've tried inspecting it but can't find a way to style it separately using className. If you have any tips, they would be greatly appr ...

Is there a way to customize the navbar layout so that link 1 is aligned to the right side, link 2 is centered, and link 3 is positioned on the right?

I attempted to utilize the flex property and justify content, but unfortunately that did not yield the desired result. I experimented with the code provided below. The goal is to create a website layout with a logo at the top and a navigation bar directly ...

Tips for maximizing website performance on touch-enabled devices

When using a touch device such as an iPhone, iPad, or Android device, it can be challenging to accurately tap on small buttons with your finger. So far, there is no universal method in CSS media queries to detect touch devices. As a workaround, I check if ...

Discrepancies in CSS3 Column Rendering Between Firefox and Chrome

My website includes an unordered list structured like this: <ul class="subnav-links"> <li class=""> <a href="/de/t/new">New In</a> </li> <li class=""> <a href="/de/t/ ...

Trigger the callback function once the datatables DOM element has finished loading entirely

Hello there! I have a question regarding datatables. Is there any callback function available that is triggered after the datatables DOM element has finished loading? I am aware of the callbacks fnInitComplete, but they do not serve my purpose. Specificall ...

How to Use CSS to Crop a String from the Middle

My file has a long name and I am using CSS text-overflow: ellipsis to crop it. <style> #fileName { width: 100px; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; } </style> <div id="fileName"> ...

Step-by-step Guide: Building a Nested Bootstrap Navigation Tabs Component on a Webpage

Within a page, I have integrated nested bootstrap navs components. The issue arises when clicking on "Nested Tab 2," which functions correctly, and then switching to "Nested Tab 1" where the tab content is not displaying properly. I am uncertain if there ...

How can a block be made to stay fixed and float in a flexbox layout?

There are three blocks within the body of this page. Title bar Content block Bottom block I have employed a flex display for the body layout. My goal is to make the title bar float, meaning it should always remain at the top when scrolling. I attempted ...

Boost your website's loading time by utilizing the async and defer attributes

Looking to enhance the speed of my webpage, particularly focusing on improving initial page speed. Research suggests that using the async and defer attributes for JavaScript can be beneficial. All JavaScript scripts are currently placed just above the cl ...

My HTML link is refusing to change color after I click on it. What could be causing

When navigating this page, the links in the Acoustid column do not change color to indicate that they have been visited. I'm unsure why this is happening, as there doesn't seem to be anything unusual in the HTML code: <tr> ...

Creating a Fully Responsive Card Design in Bootstrap 4 - Ensuring Your Card Occupies the Entire Width of the

I am trying to achieve a layout similar to the example shown here: https://i.sstatic.net/iMFx6.png The design I have in mind involves creating a card that spans the full width of the container. Inside this card, I would like to display a video on the lef ...

Exploring methods to modify the style attribute of a div tag in .NET

Using .NET, we need to access the CSS style of a div and input certain values in the code behind on page load. Since the div is located on the master page and this is another separate page, we are unable to add RUNAT="SERVER" to the div. ...

Is Jquery Mobile's Table lacking responsiveness?

I have implemented a basic table from the jQuery Mobile website on my page. Take a look at the HTML code below: <div data-role="page" id="mainPage"> <div data-role="content> <table data-role="table" id="my-table" da ...

Ways to add buttons to the navigation bar without placing them in the collapsed menu

I'm looking to add a button to the navbar with a red frame that remains visible at all times. The image above illustrates the desired button appearance. Thank you in advance to those who can assist! Image URL: <link rel="stylesheet" href="http ...

Tutorial on integrating jquery ui's '.droppable' feature with the jQuery '.on' method

I have a main div with three inner divs labeled 1, 2, and 3 as shown below: <div id="main"> <div style="height:30px; background-color:yellow;" class="bnr">Banner</div> <div style="height:30px; background-color:yellow;" class=" ...

What is the best way to position the navbar logo all the way to the left of the screen using Bootstrap?

I need to adjust the position of the logo in the navbar so that it is aligned with the far left of the screen. Currently, it is slightly off-center. I've experimented with various bootstrap classes along with the "navbar-brand" class, but haven't ...