How to position a div in the center of the screen with an overlay

While this code functions well in Firefox, it unfortunately does not work in IE.

I am seeking a solution to properly center the div on the screen - Currently, the div is leaning too much towards the bottom

In addition, I require the div with an id of "loading" to cover the entire window and prevent clicks elsewhere.

This solution must be IE-compatible.

HTML

<html>
<head>
<title>Overlay</title>
    <link href="loading.css" rel="stylesheet" type="text/css" />

    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
    <script type="text/javascript" src="loading.js"></script>
</head>
<body>
This paragraph is for testing
<br/>
Hello world!
<br/>
How are you?
<br/>
Be happy!
<br/>
<input id="cmd" type="button" value="Test" />
</body>
</html>

CSS

#loading {
    background-color: black;
    background-color: rgba(1, 1, 1, 0.7);
    bottom: 0;
    left: 0;
    position: fixed;
    right: 0;
    top: 0;
}

#loading_box {
    width: 150px;
    height: 35px;
    border: 5px solid #FFFFFF;
    padding: 5px;

    text-align: center;
    margin-top: 50%;
    margin-left: 50%;
    position: relative;
    top: -15.5px
}

#loading_img {
    width: 31px;
    height: 31px;
}

#loading_txt {
    color: #49a0dc;
    font-weight: bold;
    margin-left: 0.5em;
    font-family: "Arial Black", Gadget, sans-serif;
}

Sample file

Answer №1

Consider:

#loading_box {
    position: absolute;
    top: 50%;
    left: 50%;
    margin-top: -17px;
    margin-left: -75px;
}

instead of using position: relative; and margins with the #loading_box element. These alternative styles will make it easier to achieve the desired effect.

Answer №2

The doctype specified in your code is not correct, causing Internet Explorer to enter quirks mode. Consider using the following correct doctype declaration: <!DOCTYPE html>

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

Having trouble loading select fields using AJAX within Wordpress? Update and find a solution!

UPDATE: I am struggling to iterate through the response object and populate a select field using my ajax function. Although I have tried using a for loop instead of each(), the select field gets populated with "undefined". Any suggestions on how to resolve ...

Tips for successfully passing the selected dropdown value into contextscope within AngularJS

Hey there! I currently have a dropdown list featuring various animals. Here is the code snippet: $scope.animals = [ {value:'lion', name:'lion', description: 'lion'}, {value:'cat', name:'cat', ...

Retrieve an array of 16 elements using React in a TypeScript environment

Exploring the new React 16 feature to return array elements within the render method is throwing a TypeScript error stating "Property 'type' is missing in type 'Element[]'" const Elements: StatelessComponent<{}> = () => ([ & ...

Having trouble setting up an input tag to successfully submit the form and trigger the opening of a BootStrap Modal

Is there a way for me to submit a form to my servlet and open a BootStrap Modal simultaneously using an input tag in my .jsp file? I've tried setting the input tag type to "button" but then I can't submit the form. And when I set it to "submit", ...

Extract data from nested JSON and populate a list with corresponding values

<ul> <li><a href="" class="edit">a unique item in the list</a></li> <li><a href="" class="edit">another unique item in the list</a></li> <li><a href="" class="edit">yet another unique ...

"Material-Table does not have the ability to insert a new row

Just started learning JS and React. I'm attempting to integrate Material-table with an add row button, but encountering issues where the added row is not reflecting. Every time I refresh the page, the rows are reset. I suspect there's a problem w ...

Encountering a 404 error when utilizing ngx-monaco-editor within an Angular application

I have been encountering an issue while attempting to utilize the editor within my Angular 8 application. Despite researching similar errors on Stack Overflow and GitHub discussions, I haven't found a solution yet. Here's how my angular.json asse ...

Using JavaScript to transfer the data ID from a button to a form

I am working on a project where I have a button that triggers a modal: <button type="button" class="btn btn-primary add-subscription" data-toggle="modal" data-workspace_id="{{ workspace.id }}" data-target="# ...

What is the best way to display circles (generated from JSON data) in reverse order by incorporating a delay function?

I am currently working on creating an interactive visualization using circles that expand over a specified period, all centered at the same point. I have a script that generates these circles and saves the data in a JSON file. The smallest circle is posit ...

Tips for passing data through a modal and utilizing it in a foreach loop

Is it possible to open a modal with data from a button context in blade/laravel/bootstrap4? I have a button like this: @foreach($workflows as $workflowId =>$tasks) <button type="button" ...

Once an email address is entered, kindly instruct the driver to press the tab key twice for navigation

Adding a user to a website involves entering an email address first, which is then checked against the server's list of users. However, the issue arises when the email validation doesn't occur until clicking outside the input box or pressing tab ...

Tips for displaying the CSS3 background image on your website

My website is not displaying the background-image with the URL img/hero.jpg. I attempted using ../img/hero.jpg but still no success. Are there any solutions to this issue? I also experimented with a PDF image, but it did not work either. ...

How can I add rows to the tbody of a table that is already inside a div container?

I have an existing table and I want to append a tbody element to it. Below is an example of the HTML table: <div id="myDiv"> <table class="myTable"> <thead> <tr> <th>ID</th> ...

When the number of selected students exceeds zero, activate the collapsing feature in React

When the number of students exceeds zero, the collapse should automatically open and the text in Typography (viewStudentList) will display 'Close'. On the other hand, if the student count is zero, the collapse should be closed and the text on Typ ...

Filter products by pressing the "Enter" key while using the search input in

I have a list of products and I want to only display products that have a description or name containing the typed word when enter is clicked on the search input. Here is what I tried in my Search component: const Search = (props) => { return ( &l ...

Enabling and disabling links in a Bootstrap dropdown menu with dynamic functionality on click

One interesting feature of bootstrap is that it allows users to disable links within its dropdown menu component by simply adding a class="disabled" into the corresponding <li> tag. I am looking to create some Javascript code so that when a user sel ...

Crop the contents of an array between two specified characters

Looking to extract individual values from an array like this: "Names": [ "Name[name]", "Result[Type]", "Validation[Option]", "Status[Pointer]" ] The desired output should be: "Names": [ "name", "Type", "Option", ...

The buttons within a table row are malfunctioning following the implementation of a row click function

I am currently utilizing bootstrap 4 and have a table where each row is clickable. Within each row, there are two buttons. However, the buttons are not functioning as expected due to interference from the row click action. Here is an example of the table ...

The overflowing pop-up container

When I trigger a popup that dynamically generates a fixed background with a centered dialog, it works well. However, on smaller monitors like laptops, tablets, and phones, the content can overflow beyond the visible area due to its fixed container, making ...

Code in jQuery or JavaScript to retrieve precise node information for the currently selected form field, text, or image on a webpage

Looking to retrieve specific information about the item that has been clicked on a web page using jquery. The clickable item could be a form element (like a checkbox, text box, or text area) or a section of text within a paragraph, div, list, or image... ...