Creating a split-screen layout with Bootstrap, featuring a centrally positioned "OR" box overlay

I am facing a challenge with overlaying a box in the center of the screen on two divs that are equally split in width.

My goal is to have a simple div, possibly an image, displaying the word "OR" for user registration options. However, I'm struggling to get it perfectly centered on the page.

.or-box{position:absolute; left:45%; top:50%; z-index:99999; border:1px solid black; height:50px; width:50px; text-align:center; padding-top:15px;}

Although I expected this task to be straightforward, the div seems to shift slightly off-center when loaded.

Is there something crucial I may be overlooking when trying to position an absolute div over two other divs?

Any help would be greatly appreciated.

Here is the link to my fiddle: https://jsfiddle.net/dimmers/5fteh5tk/5/

Answer №1

To center the top (A) block vertically, you can apply the same method as centering it horizontally by using top: 50%; translateY(-50%);. For horizontal centering, simply utilize left and translateX().

left: 50%; transform: translateX(-50%);

Check out this link for an example: https://jsfiddle.net/5fteh5tk/7/

Answer №2

Being able to use left:calc(50% - 25px) is incredibly useful in certain situations.

.or-box{position:absolute; left:calc(50% - 25px); top:50%; z-index:99999; border:1px solid black; height:50px; width:50px; text-align:center; padding-top:15px;}

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

Guide to deactivating scrolling on a specific element using jQuery

Can anyone provide a solution for disabling scroll on the window but still allowing scrolling within a text area? I attempted to use the following code, but it ended up disabling everything entirely: $('html, body').css({ overflow: 'hid ...

Is there a way to add HTML line breaks using jQuery?

I'm currently working on a dynamic "posting" feature and I've been looking to integrate jQuery for smoother functionality without page refreshes. However, I've encountered an issue. Whenever a user inputs a line break in the text area, jQue ...

Enhancing the appearance of the content editor with a personalized touch

I am working with a standard content editor that utilizes an iFrame as the text area. Upon changing dropdown options, it triggers the following command: idContent.document.execCommand(cmd,"",opt); Where "idContent" refers to the iFrame. One of the dropd ...

"Effortlessly create a disappearing effect for your Bootstrap modal: Fade in upon opening, and instantly

When it comes to Bootstrap 3 modals, I have a question regarding the fade effect. On my outer modal div, I am using class="modal fade" to achieve the default fade in/out effect. However, what I really want is for the modal to fade in when opened, but disap ...

Tips for centering a video vertically within a cell

I need assistance with aligning a video in the center of a fixed height cell while hiding the overflow at the top and bottom. Here is what I have so far: <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td height ...

Challenges encountered when trying to smoothly transition between various dynamic sections on a webpage

Looking for assistance with my HTML code @if (Model.xxxs != null) { int PeriodiCnt = 0; <div class="box"> @foreach (xxxModel xxx in Model.xxxs) { PeriodiCnt++; <div class="box"> <div class="box-he ...

The function is unable to locate the variable

After I made some changes to the CSS of my game, I started encountering a variable error every time I clicked a button that called a function. The error message says it cannot find the variable. Even though I removed the CSS, the game is still not functio ...

Attempting to configure the <img> element to automatically adjust its size in accordance with the page dimensions

<center> <img style="width: 100%; max-height: 100%" src="images/ratios/3to2ratio.JPG" /> This is a traditional 35mm Still Film ratio of 3:2. </center> Although this code allows the image to scale with the page size, I prefer ...

Activate drag-enter on a parent element, excluding its child elements

Here is the code snippet I am working with: a div container with a header and body covering 100% of its surface: <div class="ui-layout--col"> <div class="ui-layout--cell-container"> <!-- $0 --> <div class=&quo ...

Turn off the href function, perform some ajax operations, then turn the href function back on

here is the issue at hand : I am facing a problem where I have a tag, and when it is clicked, the href value triggers a popup (fancybox), <a class="myIdentifier" href="#myPopup">pop</a> However, upon clicking on it, I need to perform some ...

Issues with utilizing $.getJSON

I am attempting to access the following URL through YQL http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(%22UTG.L%22)%0A%09%09&format=json&env=http%3A%2F%2Fdatatables.org%2Falltables.env& ...

How to review the current page in Joomla 2.5

Is there a way to determine the current page the user is visiting in Joomla 2.5? I have a code snippet that checks if the user is on the home page: $menu = $app->getMenu(); if ($menu->getActive() == $menu->getDefault()) { However, I now need a s ...

Displaying entered values in a text box after typing or inputting data

I am trying to display the value entered in a text box in an alert box without using any forms or buttons. However, my current code is not working as expected and it gives a null value on loading the file. HTML <tr> <td><br>Address ...

The width of the Div element is not determined by the parent CSS grid, leading to a lack of ellipsis

I am working on a grid layout where each column contains a div with text. My goal is to have the text show ellipsis when it overflows the column, even though the number of columns is random. I attempted to use the following CSS for the text-containing div ...

Tips for resolving the issue of the symbol ' displaying as &#39 in an Angular 2 application

I am currently working on an Angular application that makes API calls when a name displayed in a grid table is clicked. However, I have encountered an issue where names containing an apostrophe are being displayed incorrectly as &#39 instead. I managed ...

Utilize jQuery to locate and add items that match specific data attributes to corresponding ID elements

In my HTML code, I have a group of spans within a div that I am attempting to match and relocate to a corresponding id. Each span contains a data attribute that corresponds to the parent ID of the target element. My goal is to utilize jQuery to find the ma ...

How can I align Bootstrap 4 button toggle menu items to the right side?

One issue I am facing is with a button (class="navbar-toggler") that collapses, which works fine. However, when I click on it, all the menu items (links) appear on the left-hand side and it looks awful!!! I've tried various solutions to move the menu ...

When the Ajax done callback is not a function, it does not wait as expected

The Opening Act: After spending a few months working with traditional Ajax calls, a small error in my code today made me realize that there's still so much more to learn in this area. I find myself in need of some clarity on the matter. The Incident ...

Is it possible to post content and download at the same time with just one click

Is it possible to use AJAX to POST data and then trigger a download of the response when successful? Here is my current code: $(document).on("click", "#CSV", function () { var csv_value = $('#result').table2CSV({ delivery: 'va ...

What is the best way to divide widgets in a Wordpress Sidebar?

I am looking to customize the spacing between widgets in my Wordpress sidebar, similar to what is shown on this example site. Currently, my sidebar does not have the desired spacing. I have tried various CSS codes found online, but none of them seem to be ...