Organize your Flex-Items

Suppose there is a Flex-Box #X containing 4 Flex-Items #Y1 ... #Y4 that need to be arranged in the following manner: https://i.sstatic.net/NDix8.png If the output medium is smaller than 60em, the flex-items should be positioned like this: https://i.sstatic.net/drd9v.png

I understand what needs to be done for the HTML aspect, but how should I go about handling the CSS part?

Answer №1

Is this what you're looking for? This example showcases the use of media queries and flex-direction: column-reverse;.

.flex {
  display: flex;
  background: gray;
  justify-content: space-between;
  gap:10px;
  flex-wrap: wrap;
  padding:10px;
  max-width: 900px;
}

.item {
  margin: 0 auto;
  width:100%;
  max-width:400px;
  background-color: lightgreen;
  height:100px;
}

@media only screen and (max-width: 800px) {
  .flex {
    flex-direction: column-reverse;   
  }  
}
<div class="flex">
  <div class="item">A</div>
  <div class="item">B</div>
  <div class="item">C</div>
  <div class="item">D</div>
</div>

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

Having trouble with a static CSS file not loading correctly in the Django admin interface

Currently, I am attempting to replace the base.css file with my own custom CSS file in order to personalize the appearance of Django Admin. {% extends "admin/base.html" %} {% load static %} {% block title %}Custom Django Admin{% endblock %} {% block bran ...

I encountered an issue while attempting to fetch table data, receiving the following error message: "Uncaught TypeError: result.rows.product is not a function at products.html:134."

https://i.sstatic.net/WZ5CC.pngHere is the HTML I have written <form> <br/> <label for="products1">Product Name:</label> <input type="text" name="pdt" id="pr ...

Struggling to format XML in a tree structure for the output file

I have been attempting to accomplish this task using PHP code to save data in XML file in a tree format, but unfortunately, I have not been successful. There seems to be an issue that I can't quite pinpoint. The output continues to appear as a long st ...

Having trouble with ion-item click not functioning in Ionic 3?

Working on my Ionic 3 project, I have encountered an issue with the ion-item click listener. The scenario is that I am adding text over a canvas and then attempting to change the style of the text (such as font-family, font-size, bold, and italic). The UI ...

What is the recommended approach for linking CSS files when utilizing ASP.NET URL routing?

Within my URL routing setup, I have a master page content template that references a stylesheet on the destination page: <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server"> <link href="css/actionmenu.css" rel="stylesheet" t ...

What was the reason behind resolving the 0 height body problem by adjusting the WebView Layout Parameter?

My Xamarin WebView was not displaying my HTML correctly. Even though it was set to fill the whole screen, the body height in the HTML remained at 0px. In addition, I had a div in the HTML with the following style: position:absolute; top:0px; bottom:0px; ...

The webpage located in the res/raw/ directory

I am looking to utilize a webpage for displaying my content due to the convenient zoom and scroll features available on Android. My intention is to have the webpage stored on the sdcard so it can be accessed offline, but I am unsure how to reference it f ...

"Enhancing security measures with multiple nonce for Content Security Policy

I am encountering an issue with my single page application, which is developed in .net core MVC 2.2. The application loads html sections on the fly. In the main document, I have added a Content Security Policy (CSP) policy with a dynamically generated hea ...

The collapsible feature seems to be malfunctioning in Bootstrap

I attempted to create a button using Bootstrap that would reveal hidden content when clicked, but it doesn't seem to be working. Any suggestions or advice on how to make it function properly? <button class="bc2 border-primary bg-primary rounde ...

Verify if the web application is in full-screen mode

Currently employing a meta tag to enable full-screen mode for a web app on iPad <meta name="apple-mobile-web-app-capable" content="yes"> Is there a method available to verify whether the app is indeed in full screen? The primary objective is to ad ...

Encoding URLs in C#

Similar Question: How can I replace spaces with %20 in C#? I'm searching for a URL encoding solution in C#. While I am aware of Server.UrlEncode, I believe it encodes spaces as a + symbol. I vaguely recall another method that encodes spaces as %2 ...

You cannot use jQuery to initiate a button click event through another button click event

I'm currently facing an issue where I want to replace one button with another, but it's not going as smoothly as I hoped. When I click the first button, everything works fine. However, when I click the second button, which is supposed to trigger ...

Effective methods for increasing the height of a column div upon hovering, while also maintaining the position of surrounding columns

Struggling to make this work for 48 hours with no success. Here's the challenge: there is a standard row with regular columns that have an additional product class: <div class="row"> <div class="col-lg-4 product"> // Content ...

Hiding a div becomes impossible once it has been set to display:block

When I click on an element, I want a box to open and then when I click on a "CLOSE" button, I want it to disappear. However, I am encountering an issue where the box appears using "display:block" but does not disappear with "display:none" as intended (see ...

Sliding the content in React

My current project involves creating a content slider in React. While I have made some progress, I am facing a challenge in making the content move horizontally instead of vertically. Currently, all the items are stacked on top of each other, preventing th ...

Is there a solution for the noticeable delay in loading fonts on a web page?

I've encountered an issue in my React project where a Google font I'm using seems to briefly load as a different font before switching to the correct one. How can I prevent this from happening? This is how I'm loading the font in public/ind ...

Trigger JavaScript function when <a> element is clicked

I am looking to implement a JavaScript function that triggers when clicking on an <a> element. The initial page load will show the temperature in Celsius (°C), and users can toggle between Celsius and Fahrenheit (°F) by clicking on the temperature ...

What is the best way to align text within both the grid row and column while still maintaining the border?

When I apply justify-self and align-self rules, it successfully centers items vertically and horizontally. However, the issue arises when the borders wrap around the text instead of expanding all the way to the edges. My goal is to have a 1px border aroun ...

Browser-compatible search bar for numerical values

How can I restrict my search bar to only accept numbers in all browsers? I attempted using type="numbers", but it caused issues with the functionality of my search bar. Suggestions involving JavaScript and JQuery are appreciated. Check out the JSFiddle fo ...

Obtaining the width of an object in Three.js using CSSObject3D

In my process, I am dynamically generating HTML Dom Elements from HTML text using a specific function: String.prototype.toDomElement = function () { var wrapper = document.createElement('div'); wrapper.className = "toDomWrapper"; wrapper.i ...