Tips for avoiding divs from overlapping when the window size is modified

When I maximize the browser, everything aligns perfectly as planned. However, resizing the window causes my divs to overlap. Despite trying several similar posts on this issue without success, I have decided to share my own code.

CODE:

$(document).ready(function(){

for(var i = 1; i <= (32*16); i++){
$('.container').append("<div class=\"squares\" ></div>");

}
var $sqrs = $('.squares');
$sqrs.height("32px");
$sqrs.width("32px");
$sqrs.css("background", "#969696");
$sqrs.css("float", "right");
$sqrs.css("border-style", "solid");
$sqrs.css("border-width", "0");

$sqrs.on("mouseenter", function(){
$(this).addClass("sqr1");
$('.sqr1').css("background", "grey");
});

$('.item').click(function(){
var numSqrs = parseFloat(prompt("How many squares do you want? (1-"));
})

})
body{
width: 100%;
margin: auto;
}

.wrap{
margin-left:auto;
    margin-right:auto;
    width:100%;
display: inline-block;
}

.top {
  position: relative;
  top: 0;
  left: 0;
  z-index: 999;
  width: 100%;
  height: 55px;
  border-bottom: 1px solid #A3A3A3;
  -webkit-box-shadow: -1px 2px 12px 0px rgba(0,0,0,0.15);
  -moz-box-shadow: -1px 2px 12px 0px rgba(0,0,0,0.15);
  box-shadow: -1px 2px 12px 0px rgba(0,0,0,0.15);
  display: inline-flex;
 }
.bottom{
margin-left:auto;
margin-right:auto;
width:100%;
position:relative;
display: inline-flex;
height: auto;
}
.container{
height: 512px;
width:1024px;
position: fixed;
left:20%;
border: 1px solid #A3A3A3;
top: 10%;
-webkit-box-shadow: 28px 36px 73px -13px rgba(0,0,0,1);
-moz-box-shadow: 28px 36px 73px -13px rgba(0,0,0,1);
box-shadow:28px 36px 73px -13px rgba(0,0,0,1);

}
<!DOCTYPE html>
<html>
<head>
<title>Unique Javascript/jQuery Project Title</title>
<link rel="stylesheet" type="text/css" href="unique-styles/main.css"/>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script type="text/javascript" src="scripts/jquery-1.0.min.js"></script>


</head>
<body>
<div class="wrap">
<div class="top">
<div id="box">
<img class="head" src="images/unique-image.png"/>
</div>
<p class="Odin">The Unique Odin Project</p>
<p id="proj" class="Odin">Harsimran Mann's Unique Etch-A-Sketch Project</p>
</div>
<div class="bottom">
<div class="scd">
<div class="menu"> 
<div class="item">
<img id="trash" src="images/unique-grid-image.png"/>
<span class="item1"> New Grid </span>
</div>
<div class="item">
<img id="trash" src="images/unique-trash-image.png"/>
<span class="item1"> Clear </span>
</div>
</div>
<div class="container"></div>
</div>
</div>


</body>
</html>

Answer №1

Have you experimented with using media queries, similar to the ones shown below?

@media all and (max-width: 359px) and (min-width: 300px){ 
}
@media all and...

Answer №2

To ensure responsiveness, utilize media queries in your design. If you're struggling with the concept, consider using percentages for width and height rather than pixels. Percentages factor in the window size when determining dimensions.

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

What is the most efficient way to post an array and iterate through it using PHP?

As the user types into an input field, jQuery's replace function is used to immediately create an array. The objective is to send these values to PHP for a live search on a specific MySQL table. I've managed the input field and the ajax call, bu ...

The declaration of the 'type' in NestJS goes unused, according to ts(6133)

I have a code snippet where the keyword 'type' is highlighted in red and triggering an error message: 'type' is declared but its value is never read.ts(6133) The snippet of my code looks like this: @ManyToMany(type => RoleEntity, ro ...

Ways to identify when the socket has been opened by the client?

When utilizing socket.io on the client browser side, is there a way to identify when the socket connection has been successfully opened? I am also interested in monitoring other standard messages such as errors and disconnections. In comparison to the Web ...

The automated Login Pop Up button appears on its own and does not immediately redirect to the login form

Hey guys, I'm struggling with modifying the jquery and html to ensure that when the login button is clicked, the login form pops up instead of displaying another login button. Another issue I am facing is that the login button seems to pop up automati ...

Flexbox can be incorporated with a slide down animation to create

Currently I am attempting to replicate the "slideUp" and "slideDown" features in jQuery while utilizing a flexbox for display! jQuery.fn.toggleFlexbox = function() { var elm = $(this[0]); if(elm.css('display') === "none"){ elm.cs ...

Merge two arrays based on date and sort them using Angular.js/JavaScript

I am facing a challenge where I have two JSON arrays, each containing a field named date. My goal is to compare the two arrays and merge them into a single array. Check out the code snippet below: var firstArr=[{'name':'Ram','date ...

Unraveling nested JSON Response in Struts 2 jQuery <sj:select> tag - A step-by-step guide

Currently, I am developing a web application that utilizes Struts2 and its jQuery Plugin. The <sj:select> tag in my code below works perfectly when the JSON response is not nested: <s:url id="remoteurl" namespace="/XYZ" action= ...

Creating a unified border style for both <p> and <ul> tags in HTML5

Is there a way to have both paragraphs and unordered lists contained within the same border? I initially thought I could achieve this by placing the list inside the paragraph tag, but that does not seem to work. Below is a snippet of my external style sh ...

Tips for beginning with running vue js examples/demos

Is it possible to test my local server side REST endpoints by using the demo here? I'm not sure where to start - any guidance on how to edit and try out the demo? For example, I've cloned this repository from https://github.com/pespantelis/vue-t ...

I am having trouble getting event handlers to work with a group of buttons in JavaScript

I'm facing a problem where I'm attempting to add event handlers to buttons stored in an array. Upon clicking a button, it should trigger a function, but for some reason, it's not working and I can't seem to identify the issue. Below is ...

Does CSS give preference to max width specifications?

Within a div, I have two child div elements. The parent container utilizes a flexbox layout, with preset maximum widths for the children as shown below: <div class="wrap"> <div class="one">Hi</div> <div class="two">my secon ...

Encountering an issue when attempting to save an excel file in Angular 8, receiving an error message that states "

When working with angular 8, I encountered an issue while trying to save an excel file. The error message displayed was as follows: ERROR TypeError: Failed to execute 'createObjectURL' on 'URL': Overload resolution failed. at Functi ...

Footer not being pushed down by content in mobile view on page

Hello everyone, Can you assist me with a query, please? My form works perfectly fine in desktop view, but it gets cut off on mobile view and I'm unsure of the reason why. Here is my code: .upload-pic { position: absolute; max-width: au ...

Using res.locals with TypeScript in Next.js and Express

In my express - next.js application, I am transferring some configuration from the server to the client using res.locals. My project is written in typescript and I am utilizing "@types/next": "^8.0.6". The issue at hand: typescript is throwing an error st ...

Why opt for ref.current over directly applying the condition?

I'm curious as to why the code uses if (ref.current && !ref.current.contains(event.target)) rather than if (!ref.current.contains(event.target) function useOutsideAlerter(ref) { useEffect(() => { // Function for click event function hand ...

JQuery Mobile Navigation with Bootstrap 3 Sidebar on the Go

While using RoR, I encountered a baffling issue. I have created a new navbar with a sidebar that only displays on mobile and not on desktop. The Turbolink is functioning properly. <%= javascript_include_tag 'application', 'data-turboli ...

Error encountered: Provider '$rootScopeProvider' is not recognized - check for typos in the syntax

I am encountering an issue with the templateUrl in AngularJS. When I input this code into my editor and execute it, everything works flawlessly: HTML: <!DOCTYPE html> <html lang= "en"> <head> <meta charset="UTF-8" /> < ...

Having trouble retrieving the attribute of an appended element in jQuery?

I am facing an issue where I am unable to retrieve the ID-attribute of an element that has been appended into my HTML. Each time I try, the result is always 'undefined'. How can I resolve this problem? jQuery('form#formular').append(&a ...

The CSS file I've linked to in my HTML (ejs) document seems to be getting

As I work on developing my app from the backend, I am encountering an issue with loading CSS locally on my page. I am utilizing Node.js, Express.js, and EJS for my pages - part of the MEN/MEAN stack. <link href="../public/stylesheets/style.css" rel="st ...

When using the map function, I am receiving an empty item instead of the intended item based on a condition

Need assistance with my Reducer in ngRx. I am trying to create a single item from an item matching an if condition, but only getting an empty item. Can someone please help me out? This is the code for the Reducer: on(rawSignalsActions.changeRangeSchema, ...