Having trouble grasping the concept of div positioning and dealing with overflow problems in CSS

I am struggling to figure out why some of my DIVs are not expanding to match the height of my "content" DIV. It must be resolved using only CSS and HTML.

VISUAL IMAGE (IMGUR)

HIERARCHY

-[+]wrapper
----[-]left (will contain navigation bar)
----[-]right (used for centering the "center" div, may have content)
----[-]center (page center containing main content)
--------[o]header (small line of text)
--------[o]content (should expand all other heights when overflowing)
----[-]footer (resource & contact links, always at bottom)

CSS

  *{
        font-family: Arial Black,Arial Bold,Gadget,sans-serif;
        font-size: 12px;
        font-style: normal;
        font-variant: normal;
        font-weight: 400;    
        border:0px;
        margin:0px;
        padding:0px;
    }
    .wrapper{
        position:absolute;
        width:100%;
        height:100%;
        background-color:black;
    }
    .left{
        position:absolute;
        left:0px;
        width:220px;
        height:100%;

        background-color:red;
    }
    .right{
        position:absolute;
        right:0px;
        width:220px;
        height:100%;

        background-color:blue;
    }
    .center{
        position:absolute;
        right:220px;
        left:220px;

        background-color:yellow;
    }
    #header{
        float:left;
        height:40px;
        width:100%;
        background-color:silver;
    }
    #footer{
        position:absolute;
        bottom:0px;
        height:20px;
        width:100%;

        background-color:silver;
    }
    #content{
        float:left;
        top:40px;
        bottom:20px;
        margin:20px;

        background-color:orange;
    }

HTML

<body>
    <div class="wrapper">
        <div class="left">
        </div>
        <div class="right">
        </div>
        <div class="center">
            <div id="header">
            </div>        

            <div id="content">
            </div>

        </div>
        <div id="footer">
            </div>
    </div>
</body>

View the code on JFIDDLE here: JFIDDLE

Answer №1

Setting the .wrapper div's position to absolute and height to 100% causes it to only take the height of the container in which it is placed (this is how absolutely positioned elements work).

The issue here seems to be an over-reliance on absolute positioning. While it is a powerful tool, it may not be the best choice for layout compositions. You could consider using a float-based layout, or inline blocks, or flex layouts.

A flex layout example would look like this:

.wrapper {
display: flex;
}

.left {
  flex-grow: 1; 
}
.right {
  flex-grow: 1; 
}
.content {
  flex-grow: 3; 
}

You can also place the footer outside of the wrapper or add another child div within the structure like so:

<div class="wrapper">

    <div class="main">
          <div class="left"></div>
          <div class="right"></div>
          <div class="center"></div>
    <div>

    <div id="footer"></div>

</div>

Simply add the flex property to the main element and set the flex grow for its children.

Keep in mind that flex works based on ratios - the CSS above indicates that the .content dive will take up 3 times the width of the .left or .right dives.

For instance, 20% width for left, 20% width for right, and 60% width for center.

Answer №2

.row {
  display: flex; /* ensure equal height for children */
}

.col {
  flex: 1; /* also, ensure equal width */

  padding: 1em;
  border: solid;
}
<div class="row">
  <div class="col">Lorem ipsum dolor</div>
  <div class="col">Lorem ipsum dolor sit amet</div>
</div>

Click on this link to find the solution, or consider Javascript if you prefer not to use CSS. You can also try using this jquery plugin - jquery-match-height

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

How can I show hidden column names in the Sencha Touch 2 date picker component with CSS?

I am currently utilizing a date and time picker that has the ability to display ['month', 'day', 'year','hour','minute','ampm']. You can find the source code here. Although everything is function ...

Create a Bootstrap Modal that is positioned relative to a specific column

My design consists of 3 columns, and I need to insert a modal into the second column. The challenge is ensuring that the modal stays within the confines of the 2nd column when the screen size changes, specifically for desktop sizes ranging from 1922x1080 t ...

Understanding the error code: "400 - Bad Request"

Intentionally triggering a bad request from my backend, the express-based backend is responding appropriately with: [...] .catch((error) => { res.statusCode = 400; res.json({ msg: "This is some error", err: error, }); }); I&apo ...

In HTML5, I am trying to figure out the best way to connect my webpage sections to the corresponding navigation links with the help of IDs (such as linking navhome to

I am in the process of redesigning a website to optimize it for mobile devices. Although I have completely restructured the site, I am encountering an issue where the main pages are not displaying properly. The header, navigation menu, sidebars, and a plac ...

I am trying to verify my code, but the messages are not displaying under the username. They only appear under the password field. I am not sure where I have made a mistake

Having trouble with my login form validation using jQuery. Can someone help me fix it? $(document).ready(function() { $("#form1").validate({ rules: { username: { required: true, minlength: 6 }, password: { ...

Changing the background color of the dropdown button in Vue Bootstrap: A step-by-step guide

I've been struggling to modify the background color of a dropdown button, but no method seems to work. I've attempted changing it by using ID, removing its class and applying a new one, and even using !important to override the styles, but the ba ...

utilizing a single occasion for various purposes

I have the following buttons: <input class="btnRating" type="button" value="Project Rate" /> <input class="btnRating" type="button" value=" Education Rate" /> <input class="btnRating" type="button" value="Achievement Rate" /> I ...

Text in a class button that is not skewed

I crafted a button for my website using a CSS class, aiming for a parallelogram shape by utilizing the skew function. The code worked like a charm, giving the button the desired shape. However, I encountered a dilemma where the text inside the button also ...

Incorporate Text, HTML, and Embed Images into PHPWord

I am currently utilizing PHPWord to create word documents using PHP. I have a specific content format that I need to adhere to, as shown below: Title Description Image1 Image1 Description(HTML CONTENT) Image2 Image2 Description(HTML CONTENT) As of now ...

How can you make a select list appear or disappear based on the selection made in another select list?

I currently have a select list set up like this: https://i.sstatic.net/o730z.png What I would like to achieve is for the second select list to only appear once a selection or change has been made in the first select list. Additionally, when a selection o ...

Background-filter glitch causing display issues

I'm having trouble with the backdrop-filter property in my code. The filter I added doesn't seem to be working and I can't figure out why. Here's the snippet of my code : .army_selection { margin: 20px; margin-left: 10px ...

Ways to "halt" an element once reaching a different element while scrolling

I'm attempting to recreate the interactive widget titled "Engage. Involve. Connect" found on this webpage: . The concept involves the widget remaining fixed at the bottom of the page until the user scrolls, at which point it dynamically positions itse ...

The problem of a static click function not working when clicked on a link. What is the solution for this

Details I am currently using a flickity slideshow that automatically goes to the next picture on a click. Within the slideshow, I have placed a button with text and a link to an external website (e.g. ). My Problem: When I click on the link, my slidesho ...

The CSS filter "progid:DXImageTransform.Microsoft.Alpha(style=1,opacity=80)" is not functioning properly in Firefox

Trying to apply a filter effect using CSS but encountering issues in Firefox: progid:DXImageTransform.Microsoft.Alpha(style=1,opacity=80 ) opacity: 0.5; -moz-opacity: 0.5; Any s ...

How can I create a new div element for every item in an array by utilizing JSX?

I am currently working on creating a div element for each item in an array using reactjs JSX. I wasn't sure how to tackle this, so I attempted the following approach: {results.map((element, index) => ( <div key={index} className={ ...

Unable to change the alignment to the left in the CSS styling

My table has th elements with a text-align: left property. I tried to override this with text-align: center in my CSS, but it's not working. Can anyone suggest a reason why? Here is my table: <table class="days_table" align="center"> <thea ...

Creating an Eye-catching Presentation: Tips for Adding Text to Your CSS3 Slideshow

I am currently in the process of creating a CSS3 slideshow with text for each image. I found inspiration from this example: . However, I made some modifications to make it responsive. Here is the HTML code I have used: <div id="slideshow"> < ...

Creating a mouse-resistant div with a magnet-like effect

Looking for a way to make a circle move like a magnet effect when the mouse is near, causing elements underneath it to be exposed. If you want to see an example, check out this fiddle link: http://jsfiddle.net/Cfsamet/5xFVc/1/ Here's some initial c ...

Having trouble with a jumpy carousel? After each transition, it seems like the image is hopping within the frame, getting smaller and then bigger

As I am still new to coding and using tools like bootstrap and Dreamweaver, I encountered an issue with a carousel on my website. Everything was working smoothly until the images started losing the bottom half when auto-scrolling or clicking to scroll righ ...

ng-model to interact with dynamically loaded elements

My dynamic list contains various items, such as cars, and is not of fixed length. Upon loading, the list appears as follows: itemList = [ { id: 0, name: 'bmw' }, { id: 1, name: 'audi' }, { id: 3, name: 'vw' }, ...