Overlapping of Divs occurs when the Window size is adjusted

Looking for a solution to keep my divs in place and prevent them from moving around when resizing the window.

Below is the CSS causing the issue:

#Main {
  font-family: Arial;
}

#Intro{
  width: 70%;
  height: 1000px;
  background: rgba(255, 250, 250, 0.5);
  border-radius: 10px 10px 10px 10px;
  -moz-border-radius: 10px 10px 10px 10px;
  -webkit-border-radius: 10px 10px 10px 10px;
  border: 0px solid #000000;
  -webkit-box-shadow: 10px 10px 5px 0px rgba(0,0,0,0.75);
  -moz-box-shadow: 10px 10px 5px 0px rgba(0,0,0,0.75);
  box-shadow: 10px 10px 5px 0px rgba(0,0,0,0.75);
  padding-top: 20px;
 position: relative;
}

nav {
  width: 15%
  position: fixed;
  float: left;
  background: rgba(255, 250, 250, 0.5);
  border-radius: 10px 10px 10px 10px;
  -moz-border-radius: 10px 10px 10px 10px;
  -webkit-border-radius: 10px 10px 10px 10px;
  border: 0px solid #000000;
  -webkit-box-shadow: 10px 10px 5px 0px rgba(0,0,0,0.75);
  -moz-box-shadow: 10px 10px 5px 0px rgba(0,0,0,0.75);
  box-shadow: 10px 10px 5px 0px rgba(0,0,0,0.75);
}

twitter {
  width: 15%;
  float: right;
  background: rgba(255, 250, 250, 0.5);
  border-radius: 10px 10px 10px 10px;
 -moz-border-radius: 10px 10px 10px 10px;
 -webkit-border-radius: 10px 10px 10px 10px;
  border: 0px solid #000000;
  -webkit-box-shadow: 10px 10px 5px 0px rgba(0,0,0,0.75);
  -moz-box-shadow: 10px 10px 5px 0px rgba(0,0,0,0.75);
  box-shadow: 10px 10px 5px 0px rgba(0,0,0,0.75);
}

I have three nested Divs within my Main Div that overlap when the screen size changes or resolution is smaller. I suspect it's a simple mistake on my end, but I'm stuck at this point.

Answer №1

If I'm understanding correctly, you're looking for a column layout?

<center>
  <div id="Main">
    <nav id="nav">Navigation goes here</nav>
    <div id="twitter">Twitter goes here</div>
  </div>
</center>

#main {
  width: 100%;
}

#nav,
#twitter {
  float: left;
  color: #fff;
}

#nav {
  width: 30%;
  background: blue;
}

#twitter {
  width: 70%;
  background: green;
}

This example sets up a two-column layout with navigation on the left and "Twitter" on the right. If you want to add another column, simply include it as a child of #main and adjust the column widths accordingly (#nav, #twitter, and your third column).

To customize the size or order for smaller screens, use media queries. Here's an example:

@media screen and (max-width: 600px) {
    #nav,
    #twitter {
        float: none;
        width: 100%;
    }
}

Additionally, I noticed you tried using as an element in your HTML. Custom HTML elements may not work in all browsers, especially older ones (unless using a polyfill/library like Polymer). Stick to standard HTML5 elements for better compatibility.

Answer №2

If your concern is about preventing divs from resizing when the window screen changes, one possible solution is adjusting the CSS code from:
width: x%;
to:
width: xpx;
Alternatively, you can address this issue post-page rendering by using the min-width attribute. This could potentially resolve the problem.
min-width: xpx;
or
min-width: x%;

Answer №3

Can you please provide the HTML code you are currently using? It's possible that you may have forgotten to include the meta viewport tag. Alternatively, switching to pixel values instead of percentages (as suggested by Juan Carlos) can prevent the width from changing:

#Main {
    width: 800px;
}

On a side note, I recommend checking caniuse.com for browser prefixes. You might not need all those prefixes for box-shadow and border-radius

Answer №4

Here is the continuation of the code:

Index:

<?php
echo "<center>";
echo "<div id='Main'>";
            include("banner.php");
    include("navbar.php");
    include("twitter.php");
    include("intro.php");
    include("footer.php");
echo "</div>";
echo"</center>";

?>

Navbar

<?php
echo "<nav>
<table>
<tr>
<td>
        <ul>     
            <li><a href= 'index.php' class='LinkHome'/></a></li>       
            <li><a href= 'products.php' class='LinkProduct'/></a></li>
            <li><a href= 'fitch.php' class='LinkFitch'/></a></li>
            <li><a href= 'argodealers.php' class='LinkArgo'/></a></li>
            <li><a href= 'about.php' class='LinkAbout'/></a></li>
            <li><a href= 'contact.php' class='LinkContact'/></a></li>
        </ul>
</td>
</tr>


</table>

</nav>";
?>

Twitter

<?php
echo "
  <twitter>             
    Twitter Stuff would go here
  </twitter>";
?>

I realize it may look disorganized.

At one point, I removed two of them from Divs to experiment [adjusted CSS accordingly] - and this approach yielded better results

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

Reposition div when clicked

I have encountered a challenge where I am unable to perform a small task. My goal is to have the position of "div1" change upon clicking on "div2", taking into account that "div2" is nested inside "div1". Additionally, when clicking on "div2" again, "div1" ...

continuously repeating css text animation

How do I create an animation loop that slides infinitely, repeating non-stop in full screen without breaking at 'hello5'? I want to display 3 rows of the same item from my items array. Not sure which CSS is causing the issue. The result I am loo ...

navigating through a specific section of a data chart

I need the first column of a table to stay fixed while the rest of the columns scroll horizontally. Here's the code I have: <div id="outerDiv"> <div id="innerDIv"> <table> <tr><td>1</td><t ...

Ways to make certain HTML elements stay fixed on a webpage while allowing others to be scrollable

In this layout, the page features a navbar at the top followed by a row with two columns. The left column displays the user's profile information (such as profile picture and short bio), while the right column shows other information. However, when a ...

Inline CSS not appearing correctly upon initial page load

Is your page rendering incorrectly on the first load but then correct after a refresh? It seems to be related to the "display:inline-block" style. Despite clearing cache before loading, the issue persists and you're unable to find a solution. First L ...

In Laravel Blade, the modal content is obstructed by the Modal Backdrop on portrait screen orientation

Within my Laravel Blade, I encounter an issue where a modal pops up in portrait orientation on an iPad Pro, but is obstructed by the backdrop div. The message prompts the user to rotate the screen to landscape mode. However, the modal works perfectly in la ...

Tips for disabling scrolling on a <div> using another <div> as a lock

I am facing an issue with a page where a div is appended to the body of an HTML. The problem is that there are two scrolls appearing - one on the new overlaying div and another behind it. Here is an approximate structure of the page, how can I ensure that ...

Is it possible to use negative values in css?

Is it acceptable to utilize negative values in CSS? For instance: margin:-11px 20px -18px 0px; OR Is there a prevailing guideline that prohibits the use of negative values? ...

Can you modify a specific column in a table using mat-table in Angular material?

For my project, I am utilizing Angular Material's table to present data in a tabular format. However, due to a new requirement, I now need to enable in-line editing for the last 2 columns alongside highlighting another column when the user clicks on t ...

Is it possible to create an input field exclusively for tags using only CSS?

I am currently facing some limitations with a website I am managing. Unfortunately, I do not have the ability to incorporate additional libraries such as custom jQuery or JavaScript scripts. My goal is to customize an input field for tags so that when us ...

Positioning of buttons within a div

I am currently designing an inspiration post style: https://i.stack.imgur.com/I5J0H.png However, I am encountering some challenges while creating it: The buttons are not rounded when the window size is changed Social icons are not being displayed I am ...

After several interactions, the CSS files fail to load

I'm currently utilizing jQuery Mobile with 3 pages, and I've noticed that after navigating between the pages, the CSS is not being rendered properly. LoadCss.js $(document).on("pageinit",function(event) { $("#categoriesPage").on('pages ...

What is the reason for nesting divs within each other?

Can anyone help me troubleshoot this Django template code? I have noticed that the main-card-faq div is being rendered inside the main-card div even though it's clearly outside. Any thoughts on what might be causing this issue? {% extends 'base.h ...

What steps should I take to customize the design of my Stripe subscription payment page?

I am having trouble with the alignment of the subscription payment page, which is currently displaying all information in a single line. I would like to format it like a traditional payment form with card number, CVV, and expiry on separate lines rather th ...

ReactJS Feature: Split Screen that Can Be Moved

I am trying to create a screen with a split able and moveable feature, but I am facing difficulties in implementing it. I have tried using react split pane, but it is not working as expected. The functionality I am looking for is that when the user clicks ...

Strategies for creating a fade-in/fade-out effect that occurs only once

Having an issue with my product images. There are two stacked images and upon hovering, the top one fades out to reveal the bottom image. However, I noticed that if you repeatedly move your mouse over it like twenty times, the animation continues until all ...

Creating DIV's with Equal Heights Using AngularJS ng-repeat

I'm currently facing an issue with aligning two side-by-side divs to the same height when the content is generated using an ng-repeat function. Using flexbox is causing responsiveness issues, and I'm unsure of the appropriate time to call a jQuer ...

Learn the process of covering the entire screen with a video

I'm attempting to achieve this: IMG Below is the code snippet I've been using: <div class="container" id="containervideo"> <div id="video"> <div class="box iframe-box"> <div class="container"> ...

"Utilizing a custom CSS style for a half heart rating system

I am currently working on implementing a rating system using the font-awesome fa-heart class. While I have successfully colored the full heart, I am facing difficulty in filling only the first half of the heart in red. Despite my research efforts, all solu ...

What could be the reason that the Mui button styles are not being applied even after setting it to 'contained'?

Upon updating to the most recent version of MUI, I've noticed a problem with MUI buttons when using the contained variant. <div className="flex"> <Button variant="contained" color="primary" fullWidt ...