What is the best way to arrange these divs one on top of another?

I have combed through numerous resources but still haven't found a solution to my problem. I am struggling with figuring out how to stack the "top_section" div on top of the "middle_section" div. Currently, "middle_section" is appearing above "top_section", but ideally it should be positioned right below "top_section".

Here's the HTML

<!DOCTYPE html>

<html>
</head>
<link rel="stylesheet" href="css/main.css">

 </head>

 <body>
  <div id="wrapper">
    <div id="top_section">
     <div class="content_wrapper">

        <section id="td_left">
            <h1>XYZ</h1>
        </section>
        <section id="td_right"></section>
      </div>
    </div>

    <div id="middle_section">
        <div class="content_wrapper">
            <h1>Stuff</h1>
        </div>
    </div>

    <div id="bottom_section"></div>
  </div>

Here's the CSS:

.content_wrapper {
 width: 1100px;
 margin: 0 auto;
 background: red; }

 header {
  background: blue; }
  header img {
  width: 14%;
  margin: 0 auto 0 auto; }

 .sections, #top_section, #middle_section {
  width: 100%;
  position: absolute;
  float: left; }

  #top_section {
   height: 80.3%;
   background: #34495D; }

   #middle_section {
    height: 70.3%;
    background: #21303F; }

Answer №1

modify

.categories, #header_categories, #main_category {
    width: 100%;
    position: relative;
    display: block;
    clear: both;
}

with

.sections, #top_section, #middle_section {
    width: 100%;
    position: relative;
    display: block;
    clear: both;
}

Answer №2

Specify the starting point of the section using the "top" attribute. Remember to ensure that the combined height of all sections is 100% or less.

#top_section {
   top: 0%;
   height: 20%;
   background: #34495D; }

  #middle_section {
   top: 20%;
   height: 80%;
   background: #21303F; }

Answer №3

To solve the issue, simply remove the position: absolute from your code.

Your updated code should look like this:

sections, #top_section, #middle_section {
    width: 100%;
    float: left; }

instead of

.sections, #top_section, #middle_section {
    width: 100%;
    position: absolute;
    float: left; 
  }

Check out this fiddle for reference

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

Is it possible to manipulate videos embedded in an iframe using javascript?

It's common knowledge that JavaScript commands from Google can be used to control YouTube videos, while Vimeo provides its own JavaScript commands for their videos. Both videos are typically embedded within 'iframes' on websites. I'm ...

Is it considered a bad practice to use the record ID on a <tr> element for an editable row within a table?

I am in the process of using jQuery to create a feature that allows users to edit a HTML table containing category names. Currently, I have successfully populated my table using PHP/MySQL. While researching on jQuery - Edit a table row inline, I came acr ...

Adjust the <div> element to dynamically resize based on the user's browser changes

I need a div to adjust its width and height dynamically based on the browser dimensions when a user resizes their browser window. Implemented code following the provided suggestions: <!DOCTYPE html> <html> <head> <link rel="s ...

Parsing string to JSON object and extracting specific information

In my code, I have a variable named "response" that contains the following string: {"test": { "id": 179512, "name": "Test", "IconId": 606, "revisionDate": 139844341200, "Level": 20 }} My goal is to extract the value of the id key and store ...

I am currently encountering a glitch with my video VTT file, as the subtitles are not appearing on screen

welcome to the world of coding WEBVTT 00:01.000 --> 00:8.000 coding is my passion join me on this journey ...

Pop-up box with hyperlink

I successfully integrated multiple modals into my webpage, using a template from w3school that I customized. Now, I am curious to see if it is possible for each modal to have its unique link. For example, when I open Modal 4, the URL would change to myweb ...

Footer div is being covered by the page

I am currently working on a website built with "WordPress", and I have implemented a mobile footer plugin that is designed to only appear on mobile devices. However, I am encountering an issue where the page content overlaps the footer on phones. I attemp ...

Adding a Video as a Background Button Using HTML and CSS

My attempt to utilize background-image in CSS for the button background was unsuccessful as it only supports images, not videos. Is there a way to set a video as the background of a button? My goal is to create a button with a continuously looped muted v ...

Attempting to replicate the flipping motion of a card by applying the transform property to rotate a div element, ultimately revealing a different

I am attempting to create a series of divs that simulate the flipping action of a notecard. Unfortunately, when I hover over the div, it turns white because I have set the display property to none. I am unsure how to make the other div (.back) visible. Y ...

Keep the button in a single color unless it is being hovered over

Is there a way to create a button that changes color on hover, then reverts back to its original color after it's clicked? I'm facing an issue where my button initially has a red gradient, then changes color when hovered over, but turns white on ...

Turn off sticky sidebar feature for mobile-friendly layout

I have encountered an issue with my script that I need assistance with. I am trying to disable this script for responsive or mobile view, but despite trying various methods, it is not functioning as expected. <script type="text/javascript"> $(func ...

Struggling with implementing ng-repeat in AngularJS for displaying HTML content

I stumbled upon a post that covers pretty much what I'm trying to achieve: AngularJS - Is it possible to use ng-repeat to render HTML values? Currently, the code appears like this and displays correctly as text: <div ng-repeat="item in items.Item ...

Is it possible to adjust text wrapping based on the size of the screen?

I am currently facing an issue with my modal form where the text does not wrap properly depending on the size of the modal form. I need help with correcting this using CSS. My current approach involves using angular with new lines and hardcoding line brea ...

Tips for entering Tamil characters in text boxes on a form field

Within my form, I have a set of text boxes. I am looking to input text in Tamil font for specific text boxes - around 5 out of the total 10 text boxes in the form. If you know how to enable Tamil font input for multiple text boxes (rather than just one as ...

How to choose a particular Excel spreadsheet in Angular before importing the file?

I am currently working on a new feature that allows users to choose a specific Excel worksheet from a dropdown list before importing a file. However, I am facing some difficulty in adding the worksheet names to the dropdown list. Right now, I have placehol ...

What steps do I need to take to develop a feature similar to Tabzilla?

Exploring the innovative navigation bar on Mozilla.org seems intriguing; commonly referred to as tabzilla, it smoothly moves down to reveal the menu at the top of the page. I wonder if there are any existing libraries or ready-made jQuery code snippets tha ...

Displaying vertical content with a horizontal scroll using Bootstrap

I have created a div container and I would like to implement a horizontal scroll bar when there are more than four items (each item consists of a picture with a title). Desired outcome: The issue I am facing is that by using the code below, I end up with ...

Transferring Data Between Tables in ASP.NET Core

I'm in the process of creating a new online store with ASP.NET Core. I have a requirement to transfer data from the Products table to the Items table upon clicking a button, so that the item information can be displayed on the shopping cart page. Any ...

What is preventing my HTML/CSS code from generating a button on the webpage?

There seems to be an issue with the image on my webpage - it's displaying a broken page icon instead of the actual image, even though it was showing fine before. The image name and location have not been changed. I'm also having trouble creating ...

What is the process for updating the CSS style of every other piece of data (such as an image) retrieved

Is it possible to utilize PHP code when retrieving data from a MySQL database in order to have every other record display with unique CSS formatting? For instance, I am incorporating images similar to this in my comment system: http://prntscr.com/3hpiep ...