When adjusting the zoom level, the positioning of the div containers shifts and clashes

While working on my project, I encountered an issue with the alignment of two div boxes inside the container class. Whenever I zoom in or out on the page, the div boxes collide and change position. I have included my HTML and CSS below, but I am struggling to find a solution to keep the div boxes fixed within the container class during zooming. Any assistance would be greatly appreciated.

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type = "text/css">
*{
    margin:0;
    padding:0;
    font-family:Arial, Helvetica, sans-serif;
    }
body{
    background-color:#e1e3e4;
    }
.main{
    width:90%;
    margin: 0 auto;
    }
header{
    height:160px;
    background-color:#3c948b;
    }
.container{
    background-color: #f3f3f3;
    min-height:500px;

    }
.content{
    float:left;
    position:relative;
    top:10px;
    left:10px;
    border: 2px solid #111;
    width:70%;
    }
.panel{
    position:relative;
    float:left;
    top:10px;
    left:20px;
    border: 2px solid #111;
    width:330px;

}
</style>
</head>
<body>
<div class="main">
    <header>
        <h1>My personal blog</h1>
    </header>
    <div class="container">
        <div class="content">
            #content
        </div>
        <div class="panel">
            #panel
        </div>

   </div>
</div>
</body>
</html>

Answer №1

When your #content takes up 70% of the current window width, only 30% is left for #panel. However, since #panel has a fixed width of 330px, it cannot fit next to #content on windows smaller than about 1000px. Also, factors like borders and padding take up space, so the necessary minimum window width is even larger.

To address this issue, use relative widths for both elements (70% / 30%) and apply the box-sizing style to calculate actual widths including padding and borders (border-box).

Answer №2

Have you considered replacing the floats with a display: table approach?

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type = "text/css">
*{
    margin:0;
    padding:0;
    font-family:Arial, Helvetica, sans-serif;
}
body{
    background-color:#e1e3e4;
}
.main{
    width:90%;
    margin: 0 auto;
}
header{
    height:160px;
    background-color:#3c948b;
}
.container{
    width: 100%;
    display: table;
    background-color: #f3f3f3;
    min-height:500px;
}
.content{
    display: table-cell;
    top:10px;
    border: 2px solid #111;
    width:70%;
}
.panel{
    display: table-cell;
    top:10px;
    border: 2px solid #111;
    width:330px;
}
</style>
</head>
<body>
<div class="main">
<header>
    <h1>My personal blog</h1>
</header>
    <div class="container">
<div class="content">
#content
</div>
<div class="panel">
#panel
</div>
  
   </div>
</div>
</body>
</html>

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

Changing HTML elements dynamically within an ng-repeat using AngularJS directives

I have devised an angular directive where I execute an ng-repeat. The fundamental purpose of this directive is to interchange itself with a distinct directive that depends on a value forwarded into the original directive: <content-type-directive type=" ...

What is the best way to choose content that has been clicked on?

How do I display only clicked content? Currently, I have a system where clicking a button shows the data in the nav tag. The code is written in views.py. class TopView(TemplateView): model = Data template_name = 'index.html' def get ...

Enhance your SVG image in D3 by incorporating a drop-shadow effect

Trying to apply a drop-shadow effect to an SVG image using D3. Check out my code below and see the example block here: var imgurl = 'http://www.logo-designer.co/wp-content/uploads/2015/08/2015-Penn-State-University-logo-design-4.png'; var mar ...

"Utilizing node.js to create a custom regular expression for removing anchor tags

Can someone provide me with a regex pattern that can eliminate all the a tags from HTML and display the URL as plain text? For instance, take this text: abc <a href="http://a.com" target="_blank">bbb</a> ccccccc After applying the regex patt ...

What's the best way to ensure an endless supply of copied elements with identical classes to the clipboard?

Here is a snippet of my HTML code: <Div Class='POSTS'> <Div Class='POST'> <Div Class='CONTENT'>Text1</Div> </Div> <Div Class='POST'> <Div Class=&apos ...

PHP mail function on Godaddy hosting sending emails to spam folder instead of inbox

Currently, I am encountering an issue with the PHP mail function while using shared hosting on GoDaddy. Initially, emails were landing in the inbox successfully, but now they are being marked as spam instead. Here is the code snippet in question: <?ph ...

The height of the table cell is not being preserved properly, resulting in the background being duplicated

Currently, I am enclosing my form within a table structure. The table consists of 9 cells arranged in 3 rows and 3 columns. In this arrangement, [0,0] represents the top left corner, [1,1] is considered as main form content, and [2,2] signifies the bottom ...

Access all areas with unlimited password possibilities on our sign-in page

I have set up a xamp-based web server and installed an attendance system. I have 10 users registered to log in individually and enter their attendance. However, the issue is that on the login page, any password entered is accepted without showing an error ...

Activate anchor classes in several anchor link menus simultaneously

I have a one-page website with multiple menus filled with anchor links. Here is an example of what they look like: <ul> <li><a href="#home" class="active" onclick="closeNav();">Home</a></li> <li><a href="#abo ...

jQuery Conditional String Manipulation

I have set up a system where users can input values and make selections from a drop-down menu, which then get integrated into JavaScript code to generate customized sentences based on their inputs. Once the user clicks submit, the sentence is formed. It&ap ...

Preventing Context Menu from Appearing on Long Click in HTML5 Games

I'm attempting to utilize a similar technique as demonstrated in this stackoverflow post: How to disable the 'save image as' popup for smartphones for <input> However, I am encountering an issue where my button is not displaying at ...

The webpage is not displaying any results despite using .innerHTML with Ajax

I am currently developing a web application that displays query results using the Google Books API. While my code is functioning, I am encountering an issue where the .innerHTML method does not show any results on the HTML page. Below is the HTML code bein ...

Scroll-triggered Autoplay for YouTube Videos using JQuery

Issue: I'm trying to implement a feature where a YouTube video starts playing automatically when the user scrolls to it, and stops when the user scrolls past it. Challenges Faced: I am new to JavaScript web development. Solution Attempted: I referre ...

Tips for setting up a due date alert system

As a novice, I'm attempting to develop a function that can switch between texts based on a set due date. The text displayed will change to "Expired" once the due date is reached, and it will remain as "Active" if the date hasn't been reached yet. ...

Ways to alter the color of individual pseudo elements using a CSS loop

While working on creating a typewriter animation effect for my website using only CSS that I discovered through some online research, a question popped into my mind - is it possible to set different colors for each text in the animation? I have included t ...

Setting up ng-show in AngularJS

Looking for a solution to use ng-repeat and ng-show to organize data into two columns effectively <div class="col-md-4"> <div class="row" infinite-scroll="eventSearchService.getMoreEvents()"> <div ng-repeat="event in eventSearchService ...

Efficiently Embedding Images into Canvas Elements

I am struggling with loading individual photos from an array into "canvas" tags. In my function, I generate multiple sets of "div" tags with a "canvas" tag inside them, but I'm facing difficulties in inserting images from an array into these "canvas" ...

Modifying table design for mobile devices using Bootstrap

For desktop view, I'm aiming to have 4 columns with images positioned above the text in a similar layout to the first image (using col-3), which is quite straightforward. I currently have the image and text within the same column. https://i.sstatic.n ...

Guidelines for positioning an object to float in the bottom right of a separate tag

I am trying to position an image at the bottom right of a parent div. The CSS solution I found from another answer did not work as expected, so I had to use JavaScript to achieve the desired result. Is there a way to do this without using JavaScript? (Pl ...

The PHP SDK function works flawlessly in the local host environment and in console, however, it fails to perform on the browser when deployed

My PHP function is behaving differently between the server's command line and the web page, with successful execution on a local WAMP host. Any thoughts on what could be causing this inconsistency? function getCFTemplateSummary($CFUrl){ //init client ...