cssbulma

Bulma modal spacing on mobile


So when looking at the Bulma documentation (https://bulma.io/documentation/components/modal/), I am using the modals for both desktop and mobile but I'm having some formatting issues.

On Bulma, the mobile view doesn't add any spacing on the sides as below:
enter image description here

Does anyone know a native way to add spacing on modals for Bulma? I used px-4 which works great, but it adds the padding on desktop also, but I have the following modal structure:

<div id="mobile-profile-modal" class="modal">
    <div class="modal-background"></div>
    <div class="modal-card px-4">
        <header class="modal-card-head">
            <p class="modal-card-title"><?= $user->get_first_name(); ?></p>
            <button class="delete" aria-label="close"></button>
        </header>
        <section class="modal-card-body">
            <div class="container">
                <div class="columns is-centered">
                    <div class="column">
                        <button class="button is-fullwidth">Profile</button>
                        <button class="button is-fullwidth">Settings</button>
                    </div>
                </div>
            </div>
        </section>
        <footer class="modal-card-foot">
            <button class="button is-fullwidth is-primary">
                        <span class="icon">
                          <i class="fas fa-sign-out-alt"></i>
                        </span>
                <span>Logout</span>
            </button>
        </footer>
    </div>
</div>

Solution

  • If you don't mind overriding the linked Bulma CSS style sheet, you can do something like this:

    <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Bulma Modal Example</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.1/css/bulma.min.css">
    <style type=text/css>
        .modal-card,
        .modal-content {
            margin: 0 20px;
            max-height: calc(100vh - 160px);
            overflow: auto;
            position: relative;
            /*remove width: 100%;*/
            width: calc(100% - 2em);
        }
        /*modal breakpoint*/
        @media screen and (min-width:769px) {
            .modal-card,
            .modal-content {
                margin: 0 auto;
                max-height: calc(100vh - 40px);
                width: 640px
            }
        }
    </style>