Location of a Confirmation Box

When positioning the confirmBox on a page with lots of content using absolute inside relative positioning, I encountered an issue where the confirmBox was centered in the page but not in the center of the screen. Since the confirmBox can be opened through various links on the webpage, it is necessary to position it in the center of the screen rather than the page. How can this be achieved?

CSS

#confirmBox {
background:#fff;
border:1px solid #80686f;
border-radius:5px;
-webkit-box-shadow: 0 8px 6px -6px #766A65;
 -moz-box-shadow:0 8px 6px -6px #766A65;
box-shadow: 0 8px 6px -6px #766A65;
font-size:15px;
height:217px;
position:absolute;
text-align:center;
z-index:109;
width:400px;
top:50%;
left:50%;
margin-top:-108px;
margin-left:-200px;
}

HTML

<div style="position:relative">
<div id="confirmBox">
</div>
</div>

Answer №1

Consider using "fixed" in place of absolute

Answer №2

Recommend using fixed instead of absolute. Placing an element in the center of the whole page is not achievable with absolute positioning. In this CSS snippet, I assigned a value of *0px* to top|right|bottom|left, which effectively centers the box both horizontally and vertically.

#confirmBox {
border:1px solid #80686f;
height:217px;
position:fixed;
text-align:center;
z-index:109;
width:400px;
margin:auto;
left:0px;
right:0px;
bottom:0px;
top:0px;
}

Fiddle : JsFiddle has issues, you can check out the JsBin example (output) http://jsbin.com/uxafal/1/. To view the code, click on http://jsbin.com/uxafal/1/edit.

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

Using Bootstrap: adjusting the height of input-group and select elements

How come the select element within an input-group doesn't render similarly to the input element? I would like the height of the select element to be relative to the input-group. <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css ...

Tips for keeping several buttons in the spotlight: HTML/CSS/JS

Looking for a solution to keep multiple buttons toggled on? I'm not very familiar with JavaScript, but I know that adding a class on click won't work if there's already a class set. Maybe giving the element an ID could be a possible solution ...

How can I use jQuery to identify the numerical range within class/td/div elements and modify their CSS styles?

1# I need assistance in changing the CSS properties of a TD, Class, and div using a selector that specifies a specific number range. Specifically, I am looking to modify the css of torrent results with a seed count between 250-25000. Any torrents with a se ...

I'm having trouble aligning a bar to match the alignment of an image next to it. Instead of lining up to the right, the bar keeps widening to the left

As I construct the sidebar, I have successfully moved the image to the far right of the screen using style="text-align: right;". However, I am facing difficulty aligning a red bar in the same div along with the image. The image alignment is perfe ...

Swapping out DIVs with jQuery

Currently, I am working on a project for a client where I need to create a sortable biography section using jQuery. Initially, I had a setup with just two bios (first person and third person) which was functioning perfectly: $("a#first").click(function() ...

Develop a custom content management system that utilizes GET parameters for enhanced functionality

Creating a news system for is my current project and it consists of 3 main pages: index.php | This page displays the latest news and allows users to select which article to read article.php | Users can view the full news post on this page post.php | Thi ...

Sequentially animate objects with a fade-out and fade-in effect

Attempting to achieve a fade-out, fade-in animation using JavaScript and CSS. Here is the CSS animation code: @keyframes fade-in{ 0%{ opacity: 0%; } 100%{ opacity: 100%; } } @keyframes fade-out{ 0%{ opacity: 100%; } 100%{ opacity: 0%; } } Impleme ...

Sliding background in a multi-column accordion

I've hit a roadblock with this project. I'm working on setting up a FAQ section that needs to display its items in two columns on desktop, each with a drop shadow effect using Bootstrap 4. I've experimented with Flexbox and CSS columns with ...

Creating a custom dialog box using JavaScript

How can I create a customized dialog box in the center without displaying "the host name says..." using CSS? function myFunction() { alert("Record Save"); } Thank you in advance! ...

adjust division size proportionally to another one

I am trying to create a layout with right and left divisions where the size of the left division matches the height of the browser window (100vh). The left division consists of two sub-divisions that need to have variable sizes but collectively match the ...

How to position an element to the right in Bootstrap 4 without causing it to move to a new line immediately?

As a newcomer to Bootstrap, I have come across only one individual who has raised this issue before. Unfortunately, they did not receive a satisfactory solution, prompting me to bring up the question once more. My dilemma involves two button groups. When ...

show all the elements in a single row

My goal is to have two elements displayed in a single line. I tried implementing what I thought would work perfectly, but unfortunately, it's not quite right. Here's the issue: div#inline{ padding: 0; margin:0; display: inline-bloc ...

I'm having trouble with one of my Bootstrap modals that just won't seem to work. I've tried troubleshooting

Currently, I am in the process of developing an application that can showcase multiple Bootstrap modals. At the moment, I have successfully implemented one modal for signing out, but unfortunately, the modal designed for displaying notifications is not fun ...

Expanding upon the initial instance, the parent div effortlessly widens without any visual effects as the child element is revealed or concealed

Experiencing an issue where the div element opens and closes smoothly with jQuery animation, but its parent does not. As a result, the entire page content appears jerky. Here is a demo: http://jsfiddle.net/neDZP/7/ HTML: <div id="A_to_Z_top"> ...

Concealing a Div element without the use of Jquery or JavaScript

I have an Upper and Lower div in my HTML code. I am trying to display the Lower div only if the Upper div is present, otherwise hide it. Is there a way to achieve this using CSS without using Jquery or Javascript? Note: No modifications should be made t ...

Methods for Expanding a Div within an Oversized Row, Despite Height Constraints

I have a situation where I need to adjust the height of a cell in a table. One of the cells contains a larger element that causes the row to expand vertically. I also have another cell with a div element set to 100% of the cell's height. However, I wa ...

Achieving perfect alignment of two elements using flexbox: centering one and aligning the other to the right

Can you help me with aligning two elements to the center and right edge using flex? I am trying to achieve a layout similar to the image. XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX https://i.sstatic.net/cvmHX.png CSS Styles .flex{ display: flex; justify- ...

Using source mapping with sass-loader and postcss-loader in a Webpack configuration

I am currently attempting to activate sourceMaps in webpack, but I am encountering an issue with the combination of sass-loader and postcss-loader. When both sass-loader and postcss-loader are enabled, my console displays "no source": https://i.sstatic.n ...

Ensure that divs remain in a static position within the dialog box

Within the jQueryUI dialog, I have gray boxes at the top and bottom of the visible area represented by the .nav elements. I want these gray boxes to stay fixed in their position even when scrolling within the dialog. Despite setting position: absolute, the ...

Calculating the Distance Between Elements within a Flex Container Using JavaScript

I am looking to calculate the margin left and right for children of a flex item <div class="sec images" style="display:flex;justify-content:space-between"> <img src="images/en_mb-mega-01.png" alt=""> ...