Column that adjusts to different screen sizes

In the realm of responsive web design, what methods are suggested to achieve the specified CSS display?

My main requirement is to have a maximum of three columns. The content should be divided evenly among these three columns.

I prefer using SCSS and welcome the use of Flexbox and CSS Grids. I would like to avoid Bootstrap, even though I know it has a grid system.

For screen widths less than 1000px:

A D G
B E H
C F

For screen widths less than 500px:

A E
B F
C G
D H

For screen widths less than 200px:

A
B
C
D
E
F
G
H

Here is a link to a codepen with some initial code. I am struggling to come up with a suitable solution for this layout.

https://codepen.io/basickarl/pen/NjgvNa

I was considering using CSS Grids, but I'm concerned that it may not provide the necessary flexibility as the items in the list will change.

Answer №1

If you're unsure about what you're searching for, this solution may suit your needs.

section {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  max-width: 1500px;
}

@media screen and (min-width: 1200px) {
  section {
    background: blue;
  }
  item {
    width: 20%;
  }
}

@media screen and (min-width: 800px) and (max-width: 1200px) {
  section {
    background: pink;
  }
  item {
    width: 33.3333%;
  }
}

@media screen and (min-width: 400px) and (max-width: 800px) {
  section {
    background: yellow;
  }
  item {
    width: 50%;
  }
}

item {
  text-align: center;
  background: purple;
  margin: 1em 0em;
  align-self: flex-start;
}
<section>
  <item>One</item>
  <item>Two</item>
  <item>Three</item>
  <item>Four</item>
  <item>Five</item>
  <item>Six</item>
  <item>Seven</item>
  <item>Eight</item>
</section>

Additionally, for a n number of columns, you can use the following code:

item {
  width: calc(100%/n);
}

Answer №2

In order to accomplish my goal, I have found that creating two distinct columns is the most effective approach. The first column would contain letters A to H and be displayed initially, while the second column with the same letters would be hidden. Then, after a certain event or trigger occurs, they would switch places, showing the previously hidden column and hiding the initially visible one.

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 renderToString function in Material UI's sx property doesn't seem to have

Every time I apply sx to a component that is rendered as a string and then displayed using dangerouslySetInnerHtml, the styles within the sx prop do not work. Here is an example showcasing the issue: Codesandbox: https://codesandbox.io/p/sandbox/wonderfu ...

An issue has been discovered where IE8 is unable to print an image within the :before pseudo

Is there a way to display an icon image before text without using HTML tags like <img> that may interfere with our JavaScript code if the structure of the HTML changes? I came up with the following code which successfully displays the icon on IE8 an ...

Creating dynamic and fluid motion with Bezier curves on canvas

I am currently working on creating a line that spans across the canvas from left to right. In these early stages of development, I am using a step-by-step animation approach with the following function: timer = window.setInterval(draw_line, 30); Here is ...

Assigning a value to an input field using jQuery

I'm facing an issue while trying to set the value for an input using jQuery. Essentially, when you click on a link, it redirects you to a different page with a form, and I am attempting to set the value of one of the inputs in that form. Unfortunately ...

What is the complete pathway in CSS?

Consider this scenario: within my CSS file, there is a line of code used to display an image - specifically, a label icon located in the sidebar. background-image:url(../assets/images/icons/arrow_state_grey_expanded.png); However, due to its relative pat ...

Display 3 buttons only on screens smaller than 576 pixels, and hide them on wider screens

Struggling to get these buttons to show up, but nothing seems to work! Just stumbled upon a code that should make them visible under 576 px: However, only the navbar icon is appearing... https://i.sstatic.net/sDMJv.png I even tried consulting two AI ...

Leverage Bootstrap 4 for achieving flexible layouts and centering content with two elements using flex and justify-content

By using the d-flex, justify-content-center, and flex-grow-1 classes, I was able to achieve my desired layout with just 3 divs. <div class="row bg-primary d-flex justify-content-center"> <div class="col-auto"> LEFT </div> < ...

Should the text underneath the image be placed above the rest of the images?

In the process of developing my game, I encountered a challenge where text needs to be dragged under specific images. To achieve this, I envision creating tabs below the images for the text to be dragged onto. My initial approach involved wrapping each im ...

Ensuring form labels are properly aligned with input-group-prepend in Bootstrap

Currently, I am developing a python/django website using bootstrap, and I have encountered an issue that I cannot resolve independently. It has been quite some time since I last worked with python/django/bootstrap, so I may be overlooking something? <fo ...

Is there a way to lower just one border?

I need assistance with moving the .container div downward on my webpage. I attempted using (margin-top: 30px) and it worked, but unfortunately, it also shifted down the border of the (.container) along with the outline of .all. My goal is to have only the ...

How can I retrieve the position of a div or an image within a div (specifically the top and left coordinates) and incorporate these values into CSS?

I'm currently working on a website that is dynamic and utilizes bootstrap. I am looking to incorporate an animation where the dynamic thumbnails in the col-md-4 div zoom to 100% when clicked, appearing at the center of the container. I am struggling ...

What's the best way to use Flexbox to center a component with a "fixed width"?

As I work on my component, here is the code snippet from my highest parent, App.component: app.component.html <div class="wrapper_flex"> <div style="width:400px; background-color: pink;"></div> <div style=& ...

How can I make my Grid items in React and Material-UI occupy the entire horizontal space without wrapping to the next row?

I am currently utilizing Material-UI within a React 16.10 project. My goal is to create a table where the left column consists of an icon, while the right column displays a label and address stacked on top of each other. I want the items in the right colum ...

Ways to position Bootstrap 4 navbar elements at the bottom

Struggling to adjust the alignment of the text in the navbar items using Bootstrap 4? My initial thought was to align them at the bottom of the ul and then position the ul accordingly, but I'm facing challenges with both. The objective is to have the ...

The angular content is not scrolling

I have a basic angular content window that contains an adjustable group of settings values. When the window is collapsed, the fxLayout collapses properly, but I am having difficulty scrolling vertically. I have attempted to use overflow-y and just overflow ...

Combining Date and Time in Javascript: A Guide

As a JavaScript beginner, I am struggling with combining date and time pickers. Despite finding similar questions, I have not yet found the solution I need. I have two inputs: one for the datePicker and another for the timePicker. <form> <div clas ...

Creating a dynamic visual effect with image overlap in the Sencha Touch carousel

I've created a carousel that loads multiple images, but I'm experiencing an issue where each image is overlapping with another image from a different card. Here's a visual of the problem: As shown in the screenshot, parts of one image are a ...

What could be causing my input to not activate my function?

I am having issues with my input buttons not triggering my functions. Can anyone provide some insight into this problem? <div id="windowBar"> <h3>Imagine you were a superhero...</h3> <input id="WindowClose" type="button" onclick=" ...

Tips for sending an HTML form through Ajax, storing the data in a file, and then showcasing the results in a div

Embarking on my journey in Web Development, I am currently delving into JavaScript (specifically JQuery) and have decided to kick things off with a Simple Chat project. However, I'm facing an issue with preventing the page from refreshing after a mess ...

Maintain consistent theme across various pages using javascript

So I successfully implemented a dark mode on the front page using the following script (sourced from W3schools) : <script> function darklightmode() { var element = document.body; element.classList.toggle("dmode"); } </script> ...