Creating a CSS Flexbox Layout with alternating columns of 3 and 2

I could use some assistance with a layout that utilizes Flexbox. I'm looking for a design that transitions from 3 columns to 2 columns and then back to 3 columns. I have attached an image below to illustrate what I am referring to.

https://i.sstatic.net/lt29P.jpg

Answer №1

To achieve a specific layout, you can apply different flex sizes to elements with the `nth-child(10n + 4)` and `nth-child(10n + 10)` selectors.

.grid {
  display: flex;
  flex-wrap: wrap;
}
.item {
  flex: calc(33.33% - 10px);
  height: 70px;
  margin: 5px;
  background: #BD1522;
}
.item:nth-child(10n + 4),
.item:nth-child(10n + 10) {
  flex: calc(66.66% - 10px);
}
<div class="grid">
  <div class="item"></div>
  <div class="item"></div>
  <div class="item"></div>
  <div class="item"></div>
  <div class="item"></div>
  <div class="item"></div>
  <div class="item"></div>
  <div class="item"></div>
  <div class="item"></div>
  <div class="item"></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

What is the best way to anchor floating labels in React while incorporating Tailwind CSS?

I am currently working on developing a registration form using React and Tailwind CSS. As part of this project, I have implemented a feature where the label slides up when an input form is focused. Everything seems to be working fine up to this point. Howe ...

Parsing string to JSON object and extracting specific information

In my code, I have a variable named "response" that contains the following string: {"test": { "id": 179512, "name": "Test", "IconId": 606, "revisionDate": 139844341200, "Level": 20 }} My goal is to extract the value of the id key and store ...

"Utilize CSS GRID without the need for ::before and ::after in grid layouts

While working with CSS Grid, I noticed that the grid also includes the before and after elements as grid items. Is there a way to address this issue? .wrapper { display: grid; grid-template-columns: 100px 100px 100px; grid-gap: 10px; background- ...

Using Angular2, you can dynamically assign values to data-* attributes

In my project, I am looking to create a component that can display different icons based on input. The format required by the icon framework is as follows: <span class="icon icon-generic" data-icon="B"></span> The data-icon="B" attribute sp ...

The issue with React map causing a duplication of DOM Elements is persisting

I am encountering a particular issue: Currently, I am developing a web application with the BackEnd in spring and FrontEnd in React. The new feature I am implementing involves displaying the number of products in the cart when the client clicks on "buy". ...

Show the <li> elements and make them fade in as they come into view

I am trying to create an unordered list that behaves in a specific way: li elements that are not currently visible in the viewport should be hidden (display:none), and when they come into view, I want them to become visible and fade in. I believe I need ...

Safari does not display disabled input fields correctly

I have designed a simple angular-material form with various inputs that are organized using angular flex-layout. The form displays correctly in all browsers except for Safari on iOS devices. The problem in Safari arises when loading a form that contains d ...

Unable to function in simplistic html/php code, 'Require' fails to operate as intended

I am facing an issue while attempting to import a header.php file into my index.php file. For some reason, it is not working as expected. header.php: <!DOCTYPE html> <html> <head></head> <body> <header> & ...

Bootstrap 5 - Dropdown menu - Links unresponsive to user interaction

Often, I want to incorporate a Bootstrap 5 dropdown menu into my project, but I encountered an unexpected issue. The menu opens correctly, but when I hover over the menu items, the hover effect is not triggered, and clicking on a link does not work. It ap ...

Ensure that the child div fills the entire parent area when resizing the page

I am facing an issue with a container div that contains two elements. When I resize the window, one inner div moves under the other. However, my requirement is that when one div moves under another on resizing, the first div should occupy the full width o ...

Whenever I try to update my list of products, I encounter an error message stating that the property 'title' cannot be read because it is null

I am encountering an issue with editing data stored in the database. When attempting to edit the data, it is not displaying correctly and I am receiving a "cannot read property" error. HTML admin-products.component.html <p> <a routerLink="/ad ...

The 'id' field was anticipating a numerical value, but instead received 'bidding'

When constructing a HTML page based on a model, I encountered an issue with a form that seems to be causing interference with the model being used for building the page. The error message I received is: Exception Type: ValueError at /bidding Exception Va ...

Even after the loading spinner stops and the page appears, there is a 10-second delay where scrolling and clicking buttons are not responsive in the browser

Despite the browser's loading spinner stopping and the initial content of the page appearing ready, all buttons are unresponsive and scrolling is impossible for at least 10 seconds after the spinner stops. This page contains multiple views that are i ...

Issues with Safari not recognizing media queries

Can anyone provide some guidance on why these media queries are not working in Safari? I've tested them in Chrome and they work fine. Any help would be greatly appreciated as I'm new to coding. @media screen and (max-width: 768px) { #wellLogo ...

The button icon fails to display correctly on the iPhone X, despite appearing correctly in the DevTools

Recently, I designed a "Scroll to top" button for my application. During testing using Chrome and Safari DevTools, the button appeared correctly on all devices: https://i.sstatic.net/Apb8I.png However, upon opening it on an iPhone X, I noticed that the i ...

Never forget to login to your HTML Cookies Frame!

Looking to create a website with the following features: Two frames The first frame containing an edit box and a button The second frame displaying a secure page requiring a username and password Is it possible for a specific user to always b ...

I am interested in utilizing Selenium to interact with a hyperlink within an HTML table

I am currently using the code snippet below to fetch data from the HTML structure provided: //findTables(driver); WebElement content = driver.findElement(By.id("tblTaskForms")); List<WebElement> elements = content.findElements(By.className("form-nam ...

What is the process for altering the background color in this html5up template?

I am struggling to change the brown background color on my website. Despite updating various color values in the CSS file such as'backgroundcolor', I seem unable to make any changes. I have tried altering multiple color entries, but nothing seems ...

Vertical Alignment of Bootstrap Columns

Within the post section of my website, I have 4 columns with varying heights based on their contents using Bootstrap 4 grid system. As shown in the image below https://i.sstatic.net/ZHHqR.png When I resize the 4th column it rearranges. https://i.sstatic. ...

What could be the reason behind an Ajax Auto-Complete feature suddenly malfunctioning when moving to a new page within the same website?

Working on a website featuring an auto-complete search box powered by Ajax, Javascript, and PHP. As the user types into the search box, an ajax request triggers a php file to query a database and return possible results. Everything works smoothly until the ...