Creating a layout with CSS columns that rearranges and stacks when the browser is resized

My goal is to utilize only floats for this layout:

|A******* B******************|
|*300px * * auto            *|
|*      * *                 *|
|******** *******************|

|A*******     |
|*300px *     |
|*      *     |
|********     |
|B************|
|* auto      *|
|*           *|
|*************|

The challenge is to make Block B take up the remaining space and move below Block A when there is less than 500px of available space for it. Despite trying various combinations and solutions involving negative margins, I have not been successful.

The issue lies in the fact that CSS floats can stack vertically when no space is left, but only if a width is specified. However, when no width is specified, the block will expand to occupy all remaining space (which is what I need), but stacking becomes impossible. I require both features for Block B: taking up remaining space and moving under Block A on smaller screens.

What suggestions do you have for achieving this without using media queries or other modern features that are not supported in older browsers (such as IE8+) and without JavaScript?

This is the starting point:

<div id="blockA">
    blockA
</div>
<div id="blockB">
    <p>blockB</p>
    <p id="stopper">stopper</p>
</div>

#blockA {
    border: 1px solid powderblue;
    width: 300px;
    float: left;
}
#blockB {
    border: 1px solid khaki;
    margin-left: 300px;
}
#blockB > p#stopper {
    width: 500px;
    border: 1px solid blue;
}

Read on for the solution:

Answer №1

Here is a solution:

#blockA {
    border: 1px solid powderblue;
    width: 100px;
    float: left; /*Ensure the div B is properly floated*/
}

Answer №2

Here is the solution: To achieve the desired layout, apply float: left to the container and use overflow: hidden for blockB.

.container {
    clear: left;
}
.blockA {
    border: 1px solid red;
    width: 300px;
    float: left; 
}
.blockB {
    border: 1px solid blue;
    min-width: 500px; 
    overflow: hidden;
}

<div class="container">
    <div class="blockA">blockA</div>
    <div class="blockB">blockB</div>
</div>

This code has been tested in IE8 and FF, confirming it works as intended according to the initial question.

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

The alignment of buttons and input fields is not horizontal

How can I create a file upload option like this? | Choose File |Browse_btn| |Upload_btn| |Cancel| I've tried writing the code in HTML but I'm not getting the desired output. Here is my HTML code: <html> <head> <link r ...

Bootstrap allows for the use of video backgrounds, offering the option for borders to be included

Having trouble with a Bootstrap HTML page featuring a video background? The issue is that sometimes the video has borders on the left and right, and occasionally on mobile devices as well. Oddly enough, when the browser (Chrome or Firefox) is refreshed, th ...

Struggling with CSS selector issues

I'm relatively new to CSS and have been working on various WordPress template projects. I've encountered a seemingly simple issue that I can't seem to find solutions for in the documentation or previous questions. My apologies if this has be ...

Concealing Vimeo's controls and substituting them with a play/pause toggle button

I'm currently working on implementing the techniques demonstrated in this tutorial (), but unfortunately the code in the fiddle I put together doesn't appear to be functioning correctly. I'm at a loss as to what might be causing this issue. ...

Looking for a way to create a CSS expression to select the "Select" option? I've experimented with various x paths, but I can't seem to get it to work on

<div class="row-fluid"> <table class="s-table table table-bordered table-striped table-hover"> <thead class="p-table-head"> <tbody class="p-table-body"> <tr> <td> <td> <td> <td> <td ...

How to create a captivating image effect using CSS on hover

I am attempting to create an animated image on hover. The desired outcome is similar to the one showcased here: Check it out (scroll to view the image "Our Team") Essentially, I want a background where I can showcase information such as names and links ju ...

What steps can I take to ensure that images appear in the correct size when converting an HTML page to a PDF format?

I have noticed an issue with my web page when trying to print it as a PDF. Everything displays correctly until I reach a page with images. Strangely, the images appear with the correct width but an incorrect height in the PDF preview. The HTML code causin ...

Incorporating HTML5 audio elements in JavaScript

I am working on a project where I need to create a grid of 16 audio files with separate links for each in HTML, CSS and JavaScript. Each box in the grid should link to a different audio file. My initial thought was to use a table to achieve this, so I cre ...

Style table cells dynamically based on their content in HTML

As a complete beginner in this field, I am currently working on a simple xslt presentation file that includes a table. I want to customize the background color of either a cell or an entire row based on its content. For example, if the rating is "GOOD", " ...

Incorporating Fontello spinner icons into CSS styling

Currently, I have a background image set in the CSS and I am looking to replace it with a Fontello spinner image class. How can I achieve this? #divOverLay.show { background-color: rgba(0, 0, 0, 0.0); background-image: url('../images/spinner_ ...

How do I overwrite this calculation using JQuery?

I have a website: link There are two pages on my site that have the same div elements... I want one page to perform a certain calculation on the divs, and another page to perform a different calculation... New JavaScript Code: jQuery(document).ready(fu ...

Tips on aligning multiple elements vertically in a justified manner

I'm struggling to articulate what I need, but I'll give it a shot. I want to vertically align three different elements, each wrapped in their own divs. This is my current code: .service_info { margin-top: 45px; clear: both; ...

jquery sliding tab functionality

my jquery slide out tab is covering up my flash content Check it out here. Does anyone have suggestions on how to fix this issue? ...

Creating a flipbook out of a PDF file

I am looking for a cost-effective solution to convert my numerous PDF files into flipbooks for easy reading. I have been unable to find a free tool for this purpose, so I am curious if it is possible to create a flipbook using only HTML, CSS, and JavaScr ...

Leveraging JSON data to dynamically create HTML elements with multiple class names and unique IDs, all achieved without relying on

Recently, I've been working on creating a virtual Rubik's cube using only JS and CSS on CodePen. Despite my limited experience of coding for less than 3 months, with just under a month focusing on JS, I have managed to develop two versions so far ...

How to Align Printed Output in Angular Components

I am a beginner in Angular and I am looking to display modal information. To print the data, I am using onclick=print(). The data shows up in the print preview, but it is not aligned correctly. Here is a screenshot of my page. I want to align the data prop ...

Crafting an interactive saturation effect for mouseover interactions in a circular design

I'm looking to create a unique hover effect for my images. I have both a desaturated version and a full color version of the same image. My idea is to have mousing over the desaturated image reveal a circle spotlighting the color version underneath, a ...

Tips for deleting the drop-down arrow from Mozilla Firefox

Is there a way to eliminate the dropdown arrow that FireFox usually displays? I have included an image below showing what I am referring to: This is the CSS code I'm using: @-moz-document url-prefix(){ .class select { width: 110%; } } .class > ...

Is it advisable for postcss plugins to list postcss as a peer dependency?

I'm trying to incorporate the PostCSS Sass Color Function into my project. Unfortunately, I encountered this error: PostCSS plugin error: Your current version of PostCSS is 6.0.22, while postcss-sass-color-functions requires 5.2.18. This discrepa ...

Center the content within a div by utilizing either the auto or percentage values

Hey there, I'm currently facing some issues that I can't seem to solve. I've tried various solutions but none of them are working for me. My goal is to center the content of one div inside another. I prefer using only auto or % values as I ...