Convert a two-column layout on the web into a single-column layout for mobile devices, featuring dynamic

Is there a way to style this diagram with CSS that will work on IE11 and all major browsers?

It seems like Flexbox doesn't support dynamic height.

Do I need separate left and right columns for larger viewports and no columns for smaller viewports?

Check out the code on CodePen

<div class="container">
   <div id="box1" class="box">box1</div>
   <div id="box2" class="box">box2</div>
   <div id="box3" class="box">box3</div>
   <div id="box4" class="box">box4</div>
   <div id="box5" class="box">box5</div>
</div>

View image here

Answer №1

One method to handle different screen sizes is by using media queries to render different layouts based on the current screen size.

A Simple Example:

<html>

<head>
    <style>
        .container {
            width: 100%;
        }

        .row {
            display: flex;
            flex-direction: row;
            justify-content: flex-start;
            width: 100%;
        }

        .column {
            display: flex;
            flex-direction: column;
            justify-content: flex-start;
        }

        .item {
            width: 100%;
            border: solid 1px #dadada;
            border-radius: 16px;
            display: flex;
            justify-content: center;
            align-items: center;
        }

        @media screen and (max-width: 600px) {
            .desktop-only{
                display: none;
            }
            .column{
                width: 100%;
            }
        }

        @media screen and (min-width: 601px) {
            .mobile-only{
                display: none;
            }
            .column{
                width: 50%;
            }
        }

        .item-1 {
            height: 200px;
        }

        .item-2 {
            height: 400px;
        }

        .item-3 {
            height: 250px;
        }

        .item-4 {
            height: 300px;
        }

        .item-5 {
            height: 350px;
        }
    </style>
</head>

<body>
    <div class="desktop-only">
        <div class="container">
            <div class="row">
                <div class="item item-1">1</div>
            </div>
            <div class="row">
                <div class="column">
                    <div class="item item-3">3</div>
                    <div class="item item-5">5</div>
                </div>
                <div class="column">
                    <div class="item item-2">2</div>
                    <div class="item item-4">4</div>
                </div>
            </div>
        </div>
    </div>
    <div class="mobile-only">
        <div class="container">
            <div class="column">
                <div class="item item-1">1</div>
                <div class="item item-2">2</div>
                <div class="item item-3">3</div>
                <div class="item item-4">4</div>
                <div class="item item-5">5</div>
            </div>
        </div>
    </div>
</body>

</html>

By adjusting the breakpoint at 600px, you can observe the layout "changing" as you resize the window above and below that value.

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

I'm trying to figure out how to retrieve data from a JQuery autocomplete response that contains an array. Specifically, I want

https://i.stack.imgur.com/YpuJl.pngThis form field is for entering text input. <span> <img src="images/author2.jpg" width="50" /> //The profile picture displayed here is static but in the database I have a dynamic image. <input class="sea ...

Is it possible to integrate Google Analytics with Next.js version 13?

Is there anyone who has successfully integrated Google Analytics with NextJS 13? I tried following the steps outlined in this thread: How to implement Google Analytics with NextJS 13?, but despite doing everything as instructed, I am not seeing any data o ...

What could be the reason behind the index not getting properly set for the array that was cloned afterward?

I need assistance with a code snippet that clones an array, resets the index (0, 1, 2 ...), and stores it in a variable named buildingsPayload: console.log('1:', this.buildings) const buildingsPayload = this.buildings.map((building, index) => ...

Update the href attribute when a button is clicked

Note: The buttons in the corner will not be submitting the search. The go button would still need to be clicked to submit it. Currently, I am working on a fun project during my free time at work. This project is not meant to be anything serious, but rathe ...

How to toggling array object value in React or Redux state using Javascript/ES2015

If we have a structure like this: export default class Questions extends Component { state = { questions: [ {value: 'value one, required: true}, {value: 'value two, required: true}, {value: 'value two, required: tru ...

Tips for successfully using JSON data in AJAX requests to PHP servers

I am currently working on a project involving a shopping cart. My task is to pass an array of objects that have been added to the shopping cart and stored in localStorage over to a PHP page for database insertion. console.log(localStorage.getItem("shoppin ...

Creating a static Top Bar that remains unaffected by page refreshing using Ajax or any other method can be achieved by implementing JavaScript and CSS

I've designed a sleek top bar for my upcoming website project. Below is the CSS code snippet for creating this clean div bar: .topbar { display:block; width:100%; height:40px; background-color:#f5f5f5; } I'm looking to incorporate a simple .SWF ...

An issue occurred while attempting to utilize fs.readFileSync

Attempting to change an uploaded image to base 64 format var file = e.target.files[0]; var imageFile = fs.readFileSync(file); var encoded = new Buffer(imageFile).toString('base64'); An error is encountered: TypeError: __W ...

What is the best way to test an AngularJS directive and monitor function calls with a spy?

After running the code below, an error is thrown mentioning that element.popover is not being invoked. I can't seem to identify what the problem is. Thank you in advance for any assistance provided. directive: angular.module('directives', ...

What is the meaning of MVVM "binder" and how is it used?

I've been conducting research online to gain a deeper understanding of the MVVM architecture in general. According to Wikipedia, the key components of the MVVM pattern are: Model View View Model Binder This is the first time I have come across the ...

Replace the image source with a list of images

I am looking to create a dynamic image list using either an array or an HTML list. When I hover over an image, it should change one by one with a fade or slide effect, and revert back to the default images when I hover out. Question 1: What type of list s ...

"Utilize a custom filter in AngularJS to narrow down data based on specified numerical

Can anyone assist me in creating a filter for AngularJS data? I have two inputs, minAgeInput and maxAgeInput. I want to retrieve all products/objects (using ng-repeat) where the product's minimum age and maximum age fall within the limits set by the ...

JavaScript can retrieve the default page name that is hidden within the browser's URL

When a URL is entered without a specific file name at the end, such as "www.google.com," the server typically serves a default file like "index.html" or "default.aspx." In this scenario, if the browser displays "www.google.com," I am looking to extract the ...

Generate live references to interact with elements

I am facing a challenge in my vue app where I need to access a specific element, but there are multiple duplicate elements generated through a component. The issue is that the ref attribute only seems to work on the first component. How can I target a part ...

The issue with Firefox's DOMContentLoaded event

After creating a script that interacts with the Dom, I noticed that it needs to wait until the Dom is ready before executing each operation. My intention is to make this script usable in two ways: Include it in the head tag, ensuring it loads before the ...

What methods can be employed to maintain a consistent width for a multi-line span that aligns with the content?

Inside a div, I have 2 spans. When the content of the first span is short enough to fit on one line, the span's width matches the text content and positions the second span next to it. If the content of the first span is long and causes it to wrap, t ...

Utilizing Conditional Statements in the @artsy/fresnel Framework

I recently started working on a responsive React application using the @artsy/fresnel npm package. Below is a snippet of the code I have implemented: <Media greaterThanOrEqual='computer'> <div style={{ padding: '20px 50px' ...

Pass data from Angular UI Bootstrap Modal to parent controller upon background click or closing with the ESC key

Hello everyone. Let's dive right into the issue - I am trying to figure out how to pass a variable back from an AngularJS UI Boostrap Modal when the user clicks on the background or presses the ESC button on their keyboard. There are some solutions ...

Trouble with the Rotate <text> feature in Internet Explorer 11 on Windows 10

I am using d3.js to draw SVG with the transform:rotate(180deg) property. It displays perfectly on Chrome, but doesn't work on IE11. I tried changing it to rotateY(180deg), and it works with div elements but not with text elements. Here is my screen an ...

Are the connections from a single array unique?

A generous user shared this code with me: $singles = valley_images(); $groups = valley_group_images(); $images = array_merge($singles, $groups); $sortArray = array(); foreach($images as $image){ foreach($image as $key=>$value){ if(!iss ...