Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

evanb2's avatar

Bootstrap modal window display error

I'm trying to use bootstrap's modal windows to display some info from a DB. Everything looks good on the backend, because I can see that the correct info is being displayed when I click each button. But when the modal window displays the entire screen is grayed-out, including the modal window and I'm interact with any of the buttons on the modal window.

Could it have something to do with using Blade templating? Here is my code:

@extends('master')

@section('content')

<div class="row">
    <div class="col-md-6 col-md-offset-3" id="adventures-content">
        <h2>Adventures</h2>

        <hr>

        @foreach ($adventures as $adventure)
                <ol>
                    <!-- Button trigger modal -->
                    <button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#{{ $adventure->id }}">
                        {{ $adventure->trail_name }}
                    </button>
                </ol>

                <!-- Modal -->
                <div class="modal fade" id="{{ $adventure->id }}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                    <div class="modal-dialog" role="document">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
                                <h4 class="modal-title" id="myModalLabel">{{ $adventure->trail_name }}</h4>
                            </div>
                            <div class="modal-body">
                                <ul>
                                    <li>Trail Name: {{ $adventure->trail_name }}</li>
                                    <li>Difficulty: {{ $adventure->difficulty }}</li>
                                    <li>Rating: {{ $adventure->rating }}</li>
                                    <li>Description: {{ $adventure->description }}</li>
                                    <li>Directions: {{ $adventure->directions }}</li>
                                    <li>Length: {{ $adventure->length }}</li>
                                    <li>Loop: {{ $adventure->is_loop }}</li>
                                    <li>Date Hiked: {{ $adventure->hiked_on->diffForHumans() }}</li>
                                </ul>
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                                <button type="button" class="btn btn-primary">Save changes</button>
                            </div>
                        </div>
                    </div>
                </div>
        @endforeach

    </div>
</div>

@stop
0 likes
8 replies
Snapey's avatar

Have you been overriding any bootstrap css properties? It sounds like the mask that is supposed to block out the background is coming in front of the modal. A z-index problem perhaps.

open the page in dev tools and then inspect the modal. Set the z-index to a high number and see if it pops over the top?

evanb2's avatar

What's considered a "high" z-index? Don't have much experience with front-end stuff...

evanb2's avatar

I added this to my css:

.modal {
    position: fixed;
    padding-top: 80px;
    margin-left: 40%;
    z-index: 100;
}

still no dice...

evanb2's avatar

On a side note, is there a way to post screenshots in a thread?

Snapey's avatar

Unfortunately its impossible to say since things are stacked on the screen according to the z-index value. 2 will be over 1, 20,000 will be over 10. When the css is created the author could choose 1000 for the modal or 100. Inspecting the modal should show its current value.

The bootstrap demo at http://getbootstrap.com/javascript/#modals #mymodal has a z-index of 1050 and the grey backdrop has a z-index of 1040. If you have not altered these then it should be fine?

evanb2's avatar

I set the z-index to 500000 and it didn't change anything...

evanb2's avatar

Ok I got!! I had to move the modal window div into it's own column

OlliEngel's avatar

Hi evanb2, could you please explain what solved your problem? What do you mean with

move the modal window div into it's own column

I experience issues with my bootstrap modals/dialogs since the modal/dialog window is hidden by default with

display: none;

and at the moment I'm using a workaround to make it visible after is has been generated:

$('div[role="dialog"]').css('display', 'block');

Thanks a lot in advanced

Please or to participate in this conversation.