Adjusting the space between div elements when resizing the window

I am seeking guidance on how to ensure that the text boxes (div) on my page adjust themselves properly when the size of the page is shrunk. Currently, the text boxes tend to overlap when the screen size is smaller, which is not desirable. I need the boxes to be relative to the page and adapt to the page size accordingly. There is a drag-and-drop functionality for the text within these boxes, and I want to avoid overlap issues when the screen is smaller.

Here is a snippet of my CSS code:

#textBox1 {
    width: 22.5%;
    height: 70px;
    border: 1px solid #535353;
}

#textBox2{
    float: right;
    width: 22.5%;
    height: 70px;
    margin-left: 300px;
    margin-inline: 745px;
    margin-top: -70px;
    border: 1px solid #535353;
}

#textBox3{
    float: right;
    width: 22.5%;
    height: 70px;
    margin-left: 200px;
    margin-inline: 405px;
    margin-top: -70px;
    border: 1px solid #535353;
}

#textBox4{
    float: right;
    width: 22.5%;
    height: 70px;
    margin-left: 200px;
    margin-inline: 75px;
    margin-top: -70px;
    border: 1px solid #535353;
}
////////////////////////
//Bottom line
#textBox5{
    width: 22.5%;
    height: 70px;
    border: 1px solid #535353;
}

#textBox6{
    float: right;
    width: 22.5%;
    height: 70px;
    margin-left: 300px;
    margin-inline: 745px;
    margin-top: -70px;
    border: 1px solid #535353;
}

#textBox7{
    float: right;
    width: 22.5%;
    height: 70px;
    margin-left: 200px;
    margin-inline: 405px;
    margin-top: -70px;
    border: 1px solid #535353;
}

#textBox8{
    float: right;
    width: 22.5%;
    height: 70px;
    margin-left: 200px;
    margin-inline: 75px;
    margin-top: -70px;
    border: 1px solid #535353;
}

Here is a snippet of my HTML code:

<div id="technology-box">
    <div id="textBox1" class="react-to-dark" ondrop="drop(event)" ondragover="allowDrop(event)" data-id="autprumysl"></div>
    <div id="textBox2" class="react-to-dark" ondrop="drop(event)" ondragover="allowDrop(event)" data-id="zdravotnictvi"></div>
    <div id="textBox3" class="react-to-dark" ondrop="drop(event)" ondragover="allowDrop(event)" data-id="doprava"></div>
    <div id="textBox4" class="react-to-dark" ondrop="drop(event)" ondragover="allowDrop(event)" data-id="finance"></div>
    <br>
    <div id="textBox5" class="react-to-dark" ondrop="drop(event)" ondragover="allowDrop(event)" data-id="autprumysl_text"></div>
    <div id="textBox6" class="react-to-dark" ondrop="drop(event)" ondragover="allowDrop(event)" data-id="zdravotnictvi_text"></div>
    <div id="textBox7" class="react-to-dark" ondrop="drop(event)" ondragover="allowDrop(event)" data-id="doprava_text"></div>
    <div id="textBox8" class="react-to-dark" ondrop="drop(event)" ondragover="allowDrop(event)" data-id="finance_text"></div>
  </div>

An issue arises as shown in this example:

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

Answer №1

Incorporating Flexbox into your design is a straightforward and efficient way to create flexible layouts.

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

Resolution for Reflected Diagonal Backdrop Design

Encountering a bug in Firefox with my mirrored diagonal background pattern. A vertical line appearing between left and right positioned elements at certain screen widths. Seeking a CSS solution or hack, no linked image files allowed. .stripes-background ...

Are there any resources available for optimizing performance on iOS and Android browsers?

Being a web developer means considering the Android and iOS web browsers, which have their own rendering engines and limitations in power and memory. This can pose many complications. Therefore, I'm curious if there is a detailed guide available for ...

My objective is to show the div element just once using AngularJS

Here's the scenario I want to show this div just once, not multiple times: //angular js code $scope.arr=["sunday","mpnday","tuesday"]; //html view <ul> <li ng-repeat="x in arr"> <div><p>{{ x }}</p> </div> & ...

I seem to be invisible to the toggle switch

I currently have a toggle button that controls the activation or deactivation of a tooltip within a table. Right now, the tooltip is activated by default when the application starts, but I want to change this so that it is deactivated upon startup and on ...

The footer lies at the bottom of the page, demarcated by

I'm struggling to position the footer at the bottom of the page with a horizontal line just above it. Despite trying various resources, I can't seem to get the footer to stay at the bottom. I'm currently using a blog template as the basis fo ...

Generating HTML Tables Using PHP Arrays

Is there a recommended approach for creating a table in PHP that mimics the structure of an iOS table view or an Android ArrayList? I am looking to implement a functionality where a row can be selected and the value from that row can be retrieved, similar ...

What is the best way to line up a checkbox and its labels alongside a dropdown menu?

My index.html file has a header like this: https://i.sstatic.net/s0hAt.png I'm trying to align the checkbox and its label with the dropdown menu "In ordine". I'm using only bootstrap (no custom classes) and my current page layout is as follows. ...

Tips for accessing basic information from these websites without encountering CORS issues

Having issues retrieving data from the following two sites: and Eurolottery. The CORS issue is causing the problem, and I was able to retrieve data using a Chrome CORS extension and the provided code below: var HttpClient = function() { this.get = fu ...

How can objects be positioned or moved in a linear fashion, and how to incorporate free fall when adding additional objects?

I'm interested in creating a system similar to a "vibrating table" with linear displacement. After studying various tutorials, I was able to achieve simulations based on the following examples: Following the tutorial "Authoring a Multibody Simulatio ...

Utilizing Blurred Images in the Header

I want to create a blurred background image with text and buttons on top of it, but the blur effect is also affecting the text and buttons. I'm not sure how to keep them separate. header { background: url("street-238458.jpg") no-repeat center; ...

How to eliminate vertical spacing between rows in Bootstrap?

I am looking to eliminate the unsightly vertical spacing between the bootstrap rows displayed below: https://i.sstatic.net/dgR2z.png The code appears as follows: <div class="outerbox container-fluid vw-100"> <div class="row vw-100 justify-co ...

Struggling to set a background image for multiple div elements

Hey everyone! I'm working on a small school project website and I've run into an issue with the background on multiple div elements. Here's my HTML code snippet: <div class="bloc-1-text"> <h3> </h3&g ...

A line that shines brightest in its center, dimming slightly towards both ends

Recently, I stumbled upon some 80's retro design elements that featured glowing effects, such as this one: https://i.sstatic.net/aaJPR.png Would it be possible to recreate this glowing effect using just CSS? I'm thinking of creating a line with ...

Guide on adding JSON data from a web service whenever a function is invoked in AngularJS

I am currently calling the getData function every second and everything is working fine except for the appending functionality. Whenever the function is called, AngularJS replaces the old data with new data, but I actually want to append the new data aft ...

What is the process for storing form data into a text file?

Despite seeing similar questions in the past, I am determined to get to the bottom of why this code isn't functioning as expected. My goal is to input form data into a .txt file using a post request. While I lack extensive knowledge of PHP, I am pieci ...

React Animation Library With Smooth Initial Render and No Dependency on External Props

I'm currently implementing a Modal component within my app, utilizing Portals. My goal is for the Modal to smoothly fade in when it is rendered and fade out when it is no longer displayed. Upon examining the documentation for react-transition-group, ...

Utilizing Robot Framework to select CSS attributes

The Selenium documentation provides an example of how to use Get Element Attribute: ${id}= Get Element Attribute css:h1 id However, I encountered a problem with this selector: ${VISIBILITY}= Get Element Attribute css:visibility mySidebar I ...

Please indicate a width of 3 characters for the HTML input text

Is there a way to create an HTML text box that can only fit 3 characters exactly? I came across this code online: <input type="text" style="width: 10px; padding: 2px; border: 1px solid black"/> This code creates a text box with a width of 10px ...

Guide on sending information using ajax using a button within a form

I've been working on creating a form that utilizes HTML5 validations and integrates Ajax to show the status of mail sending. However, I'm facing an issue where clicking the send button does not initiate the expected action. Form HTML: <div c ...

Display the background-image of the <body> element only when the image has finished loading

I have a webpage where I want to delay showing a large image until it has finished downloading. Instead, I would like to display a background with a fading effect while the image loads. The challenge is that the background image must be set within the bod ...