I'm confused as to why my modal isn't appearing when the page loads

Recently, I've taken up coding as a hobby. However, I've encountered an issue with my modal not popping up on page load. Strangely, it works perfectly fine when I open a blank document but fails to load on my friend's homepage. I am using Dreamweaver CC for this project.

Here is the HTML code:

<!-- The Modal -->
<div id="myModal" class="modal">
    <!-- Modal content -->
    <div class="modal-content">
        <div class="modal-header">
            <span class="close">&times;</span>
            <h2>Update</h2>
        </div>
        <div class="modal-body">
            <h3>Hello There! We are currently closed today due to system upgrades. Please bear with us as we work tirelessly to improve our services. Your satisfaction and convenience are our top priorities, and we appreciate your ongoing support and patience.</h3>
            <h3>For live updates and menu options, follow us on Facebook.com/TheHumbleRoot and Instagram @humble_root. Thank you for your understanding and cooperation. We aim to resume operations promptly.</h3>
        </div>
        <div class="modal-footer">
            <h3>Thank you for your patience.</h3>
        </div>
    </div>
</div>

And the CSS code:

/* The Modal (background) */

.modal {
    display: block;
    position: fixed;
    z-index: 1;
    padding-top: 100px;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgb(0, 0, 0);
    background-color: rgba(0, 0, 0, 0.4);
}

/* Modal Content */

.modal-content {
    position: relative;
    background-color: #fefefe;
    margin: auto;
    padding: 0;
    border: 1px solid #888;
    width: 80%;
    box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
    -webkit-animation-name: animatetop;
    -webkit-animation-duration: 0.4s;
    animation-name: animatetop;
    animation-duration: 0.4s;
}

/* Add Animation */

@-webkit-keyframes animatetop {
    from {
        top: -300px;
        opacity: 0;
    }
    to {
        top: 0;
        opacity: 1;
    }
}

...

Lastly, here is the JavaScript code:

// Get the modal
var modal = document.getElementById('myModal');
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
    modal.style.display = "none";
}
// When the user clicks anywhere outside of the modal, close it.
window.onclick = function(event) {
    if (event.target == modal) {
        modal.style.display = "none";
    }
}

Answer №1

You might want to consider raising the z-index value of 1 to ensure it is always displayed on top, try using a higher number for better visibility.

{
 z-index:999999999;
}

Answer №2

To improve the visibility of your modal, consider changing display: "show" to display: block in the CSS for your modal class:

.modal {
     display: block;
}

The correct value for the display attribute is block, not show.

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

Issue with HTML::link() function on Laravel 5

Within one of my Controller functions, I am utilizing the code echo HTML::link('/public', 'Insert New Record');. It looks like this in the following snippet: namespace App\Http\Controllers; use App\model\Report; use ...

Dynamic jQuery snapping effect after scrolling horizontally

I'm currently working on a horizontal-scrolling site that utilizes the mousewheel jQuery Plugin. The scrolling functionality is functional, however, I am looking to implement a feature that snaps each "article" to the left side of the document when sc ...

Show content in CSS only if the div element does not contain any child elements

Is there a way to show or hide a div conditionally based on the content of another div, using only CSS? I want to avoid using JavaScript. In the past, I've used a workaround like this: .myClass:empty:before { content: 'content added to empt ...

Stopping Cross-Origin Resource Sharing (CORS) - Executing Ajax GET Requests on Ngin

I have set up Nginx as my web server and configured it as shown below: server { listen 3000; server_name .*; location / { proxy_pass http://127.0.0.1:3001; if ($request_method = 'OPTIONS') { add_h ...

The local HTTP server is having trouble establishing a connection with the Firebase user

Utilizing Visual Studio Code editor and a node js HTTP server, I have developed a simple login page and created a user in firebase. However, I encountered an issue with logging in using the username. The code for the webpage was written in HTML and bootstr ...

Can a parent div be resized to accommodate inline-block white-space nowrap content using only pure CSS?

I'm currently exploring possible solutions for making a parent div adjust its size to fit content that is deliberately set not to wrap. To better illustrate my issue, here is a jsfiddle showcasing the problem: jsfiddle.net/wtQfV Here is the code exam ...

Having trouble loading the linked CSS file in the Jade template

My directory structure is organized as follows: --votingApp app.js node_modules public css mystyle.css views test.jade mixins.jade In the file mixins.jade, I have created some general purpose blocks like 'bo ...

Triggering a table click event using jQuery

I am trying to insert a new row into a table dynamically using JavaScript and also capture the click event in the appended div class. Any ideas on how to achieve this? Here is the JavaScript code: $(document).ready(function() { $("#click").click(fun ...

The Bootstrap tooltip fails to display the visual style of the tooltip, only showing the data

Following the Bootstrap documentation for tooltips, I have tried to make the tooltip function work properly. However, when I hover over the text, the tooltip text Some tooltip text! only shows up with the alt="" function, but not styled as described in the ...

IE is causing issues with parseInt, returning NaN, while Chrome is working properly with it

When attempting to convert a date in a string to a Unix timestamp integer, I encountered an issue. While using parseInt successfully changed the string to an integer in Chrome, Internet Explorer and Edge returned NaN. If you'd like to see the code sn ...

W3C validation issue: "Failure to immediately follow a start-tag with a null end-tag" and similar errors

Encountering validation errors with the following code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <hea ...

What causes the width of a card to vary between Windows and a Macbook Pro?

Here is the code I have: <div id="app"> <v-app id="inspire"> <v-content> <v-container> <v-card max-width="1000" class="mx-auto" > <v-form v-model="valid"> ...

Utilize the CakePHP form helper to include an HTML element within a form element

I am attempting to generate a basic html output that resembles the following <button class="searchbutton" id="search_button" type="submit">--> <i class="icon-search"></i> Search</button> when using Cake PHP's form h ...

When the route is modified, the image fetched from the JSON disappears

When using a div tag to display JSON values on an image, I noticed that the values disappear when navigating to other pages and then returning to the home page. This issue is occurring as I develop with Angular.js NumberJson.get().then(function (resul ...

Is it possible to use -webkit-transform with dual background layers?

I've implemented a unique animation for a div that features two semi-transparent backgrounds: /* Custom keyframes for the animated background DIV. */ @-webkit-keyframes wind { 0% { background-position: 0px 0px, 0px 0px; } 100 ...

Ways to make two blocks of text appear side by side and adapt to different screen sizes

Check out our website imageI'm facing a challenge in making these two text elements appear next to each other rather than stacking on top of each other. Additionally, I need them to adapt responsively to changes in screen size. When 'Icontext&ap ...

absence of data returned in Ajax call for a REST endpoint

Currently, I am testing a straightforward REST service that was created using Java. The server-side code includes: import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.Produces; import ...

Alter the drag direction of the dragulaInput boxes

Yesterday, I had a question about changing the size and color of the badge and text in dragulaInput. Now, I'm wondering how to change the boxes vertically on the right side and left side. I came across <div style="display: grid; grid-column-g ...

Measuring the quantity of 'table' elements with jQuery

This HTML code below defines a table structure. Now tables can be dynamically added to this structure. <div class="tableStyle myWebsiteTable"> <table cellspacing="0" cellpadding="0" id="site0" class="site active"> <thead> ...

Ways to avoid overflow of dynamically added div element?

Currently, I am facing an issue while dynamically appending div elements with the .magnet class to my page. These elements end up overflowing the container boundaries and I am struggling to find a solution for this problem. If anyone could check out my j ...