CSS styling for header causing two columns to be pushed downwards while being absolutely positioned and stretched

After spending some time experimenting, I decided to seek help here. I am currently working on a website design with a simple layout - a header and two columns each with their own scrollbars. To achieve this setup, the columns need to have absolute positioning with specific top and bottom values set, which unfortunately takes them out of the normal document flow and causes them not to be pushed down by the header column.

If anyone has any ideas on how to accomplish this using just CSS, I would greatly appreciate it. It seems like such a straightforward task!

Best regards, Thijs.

Code:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Testcase</title>

<style type="text/css">

body {
    margin: 0;
    padding: 0;
}

#header {
    background-color: #c8ffff;

}

#lr_container {
    position: absolute;
    top: 250px;
    bottom: 0px;
    left: 0px;
    right: 0px;
}

#leftcol {
    background-color: #ffdcff;
    position: absolute;
    top: 0px;
    left: 0px;
    bottom: 0px;
    width: 200px;
    overflow-y:scroll;
    overflow-x:hidden;
}

#rightcol {
    background-color: #ffffd1;
    position: absolute;
    top: 0px;
    left: 200px;
    bottom: 0px;
    right: 0px;
    overflow-y:scroll;
    overflow-x:hidden;
}



</style>

</head>

<body>

<div id="header">
variable amount of content, needs to stretch in height and push the pink and yellow kids downwards<br/><br/>!<br/>!<br/><br/>!<br/>!<br/><br/>!<br/>!<br/><br/>!<br/>!
</div>

<div id="lr_container">

    <div id="leftcol">

    has a fixed width, stretches to the bottom of window<br/><br/>
    aa<br/><br/>
    aa<br/><br/>
    aa<br/><br/>
    aa<br/><br/>
    aa<br/><br/>
    aa<br/><br/>
    aa<br/><br/>
    aa<br/><br/>
    aa<br/><br/>
    aa<br/><br/>
    aa<br/><br/>
    aa<br/><br/>
    aa<br/><br/>
    aa<br/><br/>
    aa<br/><br/>
    aa<br/><br/>
    aa<br/><br/>
    aa<br/><br/>
    aa<br/><br/>

    </div>

    <div id="rightcol">
    stretches to the right and stretches to the bottom of window<br/><br/>
    bb<br/><br/>
    bb<br/><br/>
    bb<br/><br/>
    bb<br/><br/>
    bb<br/><br/>
    bb<br/><br/>
    bb<br/><br/>
    bb<br/><br/>
    bb<br/><br/>
    bb<br/><br/>
    bb<br/><br/>
    bb<br/><br/>
    bb<br/><br/>
    bb<br/><br/>
    bb<br/><br/>
    bb<br/><br/>
    bb<br/><br/>
    bb<br/><br/>
    bb<br/><br/>
    bb<br/><br/>
    bb<br/><br/>
    bb<br/><br/>
    bb<br/><br/>
    </div>

</div>


</body>
</html>

Answer №1

My solution to this problem would involve the following CSS code:

#leftcol {
  background-color:#FFDCFF;
  float:left;
  height:200px;
  left:0;
  overflow-x:hidden;
  overflow-y:scroll;
  position:relative;
  top:0;
}
#rightcol {
  background-color:#FFFFD1;
  float:left;
  height:200px;
  left:200px;
  overflow-x:hidden;
  overflow-y:scroll;
  position:relative;
  right:0;
  top:0;
}

With this setup, both columns (leftcol and rightcol) will move down as content expands. You can reset the float using clear: both;

<div id="leftcol">column 1</div>
<div id="rightcol">column 2</div>

<div style="clear: both;"></div>
<div id="bottom">at the bottom</div>

I hope this explanation is helpful!

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

Adjusting a Form Input Field

There seems to be an issue with the text alignment in my submission form input field, as the text appears a few pixels too low. This is causing certain letters like y, q, and j to bleed below the box in Chrome and only partially show in IE 8. To fix this p ...

Looking for some CSS to style the image below

Looking for CSS assistance to style the sample image provided below. The letter within the circular element is contained in a div while the subscript Z is represented by an image of a circle. https://i.sstatic.net/sKF1H.png .text-center { text-align: ...

What could be the reason for my Bootstrap popover malfunctioning?

I've been attempting to incorporate the Bootstrap popover into my project. I copied the code exactly from the example provided on the website, but unfortunately, it doesn't seem to be functioning properly on my site. Below is the full code snippe ...

Modify the variable to encompass a multitude of hues - scss

Hello, I am looking to modify the background of a page for dark mode. This is the current background styling: $orangeLight:#FFA500!default; $redLight:#FA8072!default; $blueLight:#B0C4DE!default; $greenLight:#90EE90!default; $list2: $blueLight 0%,$blueLi ...

Trouble Aligning Bootstrap Dropdown Menu Link with Other Navbar Links

Issue with dropdown links not aligning properly in the Bootstrap navbar. The positioning seems off and can be seen in the screenshot provided where the blue outline represents the ".dropdown" https://i.stack.imgur.com/QmG7v.png Facing a similar problem a ...

Icon and div-based carousel/slider for a unique visual experience

I have a project in progress that requires dynamically displaying icons based on the user's selection. These icons are essentially glyphs with a two-word title underneath them. Essentially, there is an <div class="col-md-9"> ...

How can I increase the fading effect more and more with each call of the event using jQuery's fadeTo()?

I'm currently working on a script that is intended to gradually fade an image from 80% opacity to 1%, but every time I click, it goes straight to the set opacity. How can I make the fading effect continuous? Any help would be appreciated. Here is the ...

What is the method for aligning images next to each other and on top of one another

Being new to html and css, I am currently working with 4 images that need to be arranged a certain way. My issue is that the pictures are stacking on top of each other instead of displaying as desired. Check out this image for reference To solve this pro ...

The Empty Spaces Surrounding the Navigation Bar in HTML/CSS

I am just starting out with CSS and HTML. Is there a way to eliminate the gaps around my navigation bar? Here is an example image showing the gaps around the navbar. I have attempted using width and height attributes but it did not resolve the issue. ...

Ensure that the tooltip is always displayed at the top of the table within a span

Hi there, I've created a table and added a tooltip using CSS. The tooltip appears when you hover over the <td> elements. If you're interested, here's the link to my JSFiddle: www.jsfiddle.net/4qzurb5w/ I'm wondering how I can m ...

When combining Symfony, Twig, and Semantic UI, users may encounter an issue where the background image fails to display

Can someone assist me in identifying the issue with my code? I am using Symfony 2.8, Semantic UI, and Twig, attempting to set a background image on my site. The modification is being made to my base.html.twig file. I have attempted: Using different ima ...

What is the best method to remove the x and up/down arrow components of an input date field?

My main objective is to have the orange triangle display in the box, but I'm unsure if CSS or another method is needed to remove the two elements on the left side of the triangle. Is there a way to achieve this? Currently, I am using the input type d ...

What is the method for placing an image beside text in javascript?

I need help creating a Sign In button similar to the one on YouTube, with an image on the left and text on the right. After attempting the code below, I realized that the image does not display as intended when executed. How can I successfully position t ...

Energetic flair for Vue animations

I am currently developing a VueJS sidebar component. The objective is to allow the parent to define a width and display a toggle button that smoothly slides the sidebar in and out. Here is an example: <template> <div class="sidebarContainer ...

Dynamic div that automatically adjusts its height ratio to fit its parent container

Imagine you have two divs (A) and (B). The parent div (A) has a height: auto and so does the child div (B). Is there a way, without using JavaScript, to make div (B) always occupy 90% of the height of div (A)? Any insights or suggestions would be greatly a ...

The feature of Switch css does not appear to function properly when used in conjunction with input type

Why does the switch button not work with the input type radio but works with a checkbox button? How can I maintain the radio input and solve this issue? @charset "utf-8"; /* CSS Document */ /* ---------- GENERAL ---------- */ body { background: #4a4a4 ...

What is the best way to align HTML inputs within a grid, whether it be done automatically or manually using JavaScript?

Arrange 20 HTML inputs with various data types into grid-columns as the user inputs data. Ensure that the grid container has div elements correctly positioned for output. ...

Obtain the rotational value in 3D CSS using JavaScript by extracting it from the matrix3d()

My element has been 3D transformed in the following way: .foo { transform: rotateX(-30deg) rotateY(35deg); } Now, I am looking to retrieve these values using JavaScript. Extracting the 3D matrix is simple: var matrix = $('.foo').css('tr ...

What is the best way to incorporate a website logo: using the <img> tag

As I work on building a practice website, I've noticed that I have an IMG tag for the website logo on every HTML subpage. I'm wondering if it would be more efficient to use a background image in CSS instead of the IMG tag? <div id="logo_w ...

Transfer the @font-face declaration from the global CSS file into the MUI Theme

In my project, I have an index.css file that includes the following @font-face declaration: //Index.css ... @font-face { font-family: "My Font"; font-style: normal; font-display: swap; font-weight: 400; src: url(/public/fonts/my-font.eo ...