By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Grid using media queries to collapse buttons from 3 to 2 to 1

code: Edit fiddle - JSFiddle - Code Playground

The buttons are not collapsing from 3 to 2 to 1.

I don’t understand why it is not working.

How do I get it to work?

@media (max-width: 536px) {
  .buttonContainerC {
    grid-template-columns: repeat(2, 183px);

@media (max-width: 172px) {
  .buttonContainerC {
    grid-template-columns: repeat(1, 183px);

.buttonContainerC {
  display: grid;
  grid-template-columns: repeat(3, 183px);
  /*align-content: center;
  justify-content: center;*/
  align-items: center;
  max-width: 569px;
  gap: 10px;
Last edited:
It's because you have already defined grid-template-columns in your main .buttonContainerC section. That is not goinf to be overwritten by the values in your @media sections.
Remove that line and add this section:

@media (min-width: 536px) {
  .buttonContainerC {
    grid-template-columns: repeat(3, 183px);

That should do it.
Here is another solution with one line, no MQs. Adjust width as needed.

Seen in action here:

From this article:

grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));

New Threads

Buy us a coffee!

Top Bottom