How come my div containers are intersecting each other exactly at the center with a height of 50% and width of 50%?

I am facing an issue where the four boxes I created are overlapping, despite being set to a height of 50vh and a width of 50vw. How can I resolve this problem and prevent them from overlapping?

https://i.sstatic.net/yRXv1.png

https://i.sstatic.net/4hra6.png

HTML (React):

<div className={styles['policyContainer']}>
    <div className={styles["foreignPoliciesContainer"]}></div>
    <div className={styles["taxPoliciesContainer"]}></div>
    <div className={styles["lawOrderPoliciesContainer"]}></div>
    <div className={styles["econTransPoliciesContainer"]}></div>
</div>

CSS (Module):


.policyContainer {
    position: absolute;
    top: 0;
    z-index: -99;
    height: 100vh;
    width: 100vw;
    background-color: #fff;
    transition: all 0.2s ease-in-out;
}

.foreignPoliciesContainer {
    clear: both;
    position: absolute;
    top: 0;
    left: 0;
    z-index: -99;
    height: 50%;
    width: 50%;
    border: 5px solid #000;
}

.taxPoliciesContainer {
    clear: both;
    position: absolute;
    top: 0;
    right: 0;
    z-index: -99;
    height: 50%;
    width: 50%;
    border: 5px solid #000;
}

.lawOrderPoliciesContainer {
    clear: both;
    position: absolute;
    bottom: 0;
    left: 0;
    z-index: -99;
    height: 50%;
    width: 50%;
    border: 5px solid #000;
}

.econTransPoliciesContainer {
    clear: both;
    position: absolute;
    bottom: 0;
    right: 0;
    z-index: -99;
    height: 50%;
    width: 50%;
    border: 5px solid #000;
}

I attempted setting the height and width of all four containers to 50%.

Answer №1

Your box dimensions are being affected by the border width. To resolve this issue, you can adjust the box-sizing property of your boxes to border-box.

.policyContainer {
    position: absolute;
    top: 0;
    z-index: -99;
    height: 100vh;
    width: 100vw;
    background-color: #fff;
    transition: all 0.2s ease-in-out;
}

.foreignPoliciesContainer {
    box-sizing: border-box;
    clear: both;
    position: absolute;
    top: 0;
    left: 0;
    z-index: -99;
    height: 50%;
    width: 50%;
    border: 5px solid #000;
}

.taxPoliciesContainer {
    box-sizing: border-box;
    clear: both;
    position: absolute;
    top: 0;
    right: 0;
    z-index: -99;
    height: 50%;
    width: 50%;
    border: 5px solid #000;
}

.lawOrderPoliciesContainer {
    box-sizing: border-box;
    clear: both;
    position: absolute;
    bottom: 0;
    left: 0;
    z-index: -99;
    height: 50%;
    width: 50%;
    border: 5px solid #000;
}

.econTransPoliciesContainer {
    box-sizing: border-box;
    clear: both;
    position: absolute;
    bottom: 0;
    right: 0;
    z-index: -99;
    height: 50%;
    width: 50%;
    border: 5px solid #000;
}

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

Verify If a Circular Element Within a Javascript Canvas Element was Clicked

As a beginner with Canvas, I am running into some issues. I have created a simple game where circles fall at a steady pace, but I am struggling to detect if a falling circle has been selected. I need assistance figuring out how to select a moving circle. ...

Selecting databases and tables on the fly in the pg-promise API

Instead of using a hardcoded initial connection object, the pg-promise API suggests creating a dynamic connection object like this: var pgp = require('pg-promise')(); const mysqlcon = `postgres://${process.env.DB_USER}:${process.env.DB_PASSWORD}@ ...

React to the scrolled items as the active object from the mapped array is displayed in the center

, the mapped data appears in a unique way on a timetable, arranged by date (30 days) in a horizontal scroll. With the current date data highlighted as active, the challenge arises when the active date is far down the list, say at the 22nd position, and onl ...

What steps can I take to display lines in a textarea so that it closely resembles the appearance of a notepad document

Is there a way to display lines in a text-area to give it the appearance of a notepad? I only have one text-area available. See the example notepad below for reference. ...

Encountered a hiccup with TSDX while trying to create a project using the react-with-storybook

My goal was to develop a UI components library using Storybook and React. This was my first time working with Storybook, so I followed the instructions provided in the documentation: I initiated the project by running npx tsdx create my-components in the ...

Displaying various image previews in separate divs from user input

Is there a way to allow users to upload multiple images from their computer and have them displayed in separate divs on the webpage? I want users to be able to select images using input fields and then see the uploaded images in different div containers. ...

Having trouble retrieving alert message after submitting form using jquery

Trying to submit a form using jQuery, but when clicking on the submit button it displays a blank page. I understand that a blank page typically means the form has been submitted, but I want to show an alert() for testing purposes instead. However, it only ...

Unlocking the key to retrieving request headers in the express.static method

Utilizing express.static middleware allows me to avoid manually listing each asset in the routes. All my routing is managed through index.html due to my use of Vue JS. However, a feature necessitates me to extract specific information from the request hea ...

Combining two array objects in JavaScript to create a single array object and iterating through each index or object

let objectArray1 = [{key1: 1}, {key2: 2}, {key3: 3}]; let objectArray2 = [{operator: LESS THAN}, {operator: GREATER THAN}, {operator: NOT EQUAL}]; In this scenario, the goal is to combine each object in objectArray2 with the corresponding object in objec ...

Unable to retrieve file on Linux system through PHP

<?php // Ensuring that an ID is provided include('include/function.php'); if(isset($_GET['id'])) { // Retrieving the ID $id = intval($_GET['id']); // Validating the ID if($id <= 0) { die('Th ...

Exploring and Troubleshooting HTML and JavaScript with Visual Studio Code Debugger

Visual Studio Code Version 1.10.2 Windows 10 I am currently experimenting with VS Code and would like to debug some basic HTML and JavaScript code. The instructional video found at http://code.visualstudio.com/docs/introvideos/debugging mentions that ...

What is the best way to trigger multiple actions from a single form in Struts 1?

Seeking assistance on how to call multiple actions from a single JSP without using ajax. I have attempted various methods, but they don't meet the standards. Can you provide guidance on calling multiple actions without ajax? <html:form action="ins ...

Learn the Method Used by Digg to Eliminate "&x=0&y=0" from their Search Results URL

Instead of using a regular submit button, I have implemented an image as the submit button for my search form: <input id="search" type="image" alt="Search" src="/images/searchButton.png" name="" /> However, I encountered an issue in Chrome and Fire ...

Display each div one at a time

I am working on a script that should reveal my divs step by step. However, the current code only shows all the divs at once when clicked. How can I modify it to detect each individual div and unveil them one by one? For example, on the 1st click => expa ...

Unable to access properties of an unknown item (reading 'remove')

Can you provide guidance on how to remove the top-level parent element of a div? I've been attempting to delete the main parent element of a specific div. element.innerHTML = ` <div class="postIt-item"> <div class="postIt-item-btn ...

Error: Unable to access the 'date' property of the 'Chat' type

chats object //I have an object containing chats retrieved from firebase date: nt nanoseconds: 269000000 seconds: 1684252737 lastMessage: {texts: 'So all the image disappears'} userInfo: {uid: '97iObwAHkQcnyq1CHgwnPg2f4Ga2', username: & ...

What sets apart the CSS file directories in a React application compared to those in an Express server?

For instance, there is a public folder that contains all the css files, and a separate view folder for ejs files. When linking the css file in the ejs file, the code usually looks like this: <link rel=”stylesheet” href=”styles.css”> or like ...

Having trouble reaching the elements stored in an array?

As a beginner in Angular and JavaScript, I may be making some obvious mistakes so please bear with me. I have written this code that allows the selection of 2 text files and then combines them into a single array. $scope.textArray = []; $scope.textUpload ...

Should Google Analytics be integrated directly or through the use of Tag Manager?

Currently in the process of developing a substantial NextJS application, I have come across the need to incorporate Google Analytics 4 for the client. Wondering whether it would be more effective to integrate Google Analytics directly into my application o ...

Adding dynamic rows in JavaScript while ensuring proper spacing

I am currently working on dynamically adding a span element with an onclick event. $.ajax({ url:path, type: "POST", contentType: false, // To avoid setting any content header processData: fa ...