My grid layout isn't behaving as expected when using media queries

My current issue involves the implementation of a "main" element with a "grid" display property. I have configured two different layouts for this grid based on the screen size, as seen in the code snippet below:


        main {
            display: grid;
            grid-template-columns: repeat(1, 1fr);
            grid-auto-rows: minmax(400px, auto);
            align-items: stretch;
            margin: 10px;
        }
        
        @media screen and (min-width:700px) {
            main {
                grid-template-columns: repeat(2, 1fr);
            }
        }
    

When the screen size exceeds 700 pixels, there should be 2 columns; otherwise, only 1 column is displayed. However, this setup does not work as intended, as evidenced by the screenshot shown below:

Image of the site at 600px

Interestingly, the layout functions correctly when the screen width is 400 pixels, but fails to do so at 700 pixels. I attempted using "max-width" instead of "min-width," but encountered the same issue where the site appears identical.

If anyone has insights into what might be causing this problem, I would greatly appreciate your assistance.

Answer №1

For screens larger than 700px, you may prefer a layout with 2 columns, while for smaller screens, a single column layout may be more suitable. To achieve this, consider using the following CSS code:

Give this approach a try and hopefully it will help solve your issue.

main {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-auto-rows: minmax(400px , auto);
  align-items: stretch;
  margin: 10px;
}

@media screen and (max-width:700px){
  main{
    grid-template-columns: repeat(1 ,1fr);
  }
}

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

Enhancing the HTML tag with extra attribute from a nested webpage

Looking to modify the <html> tag in the master page <html xmlns="http://www.w3.org/1999/xhtml"> I am trying to add an additional attribute from another page that utilizes this master page. My goal is to end up with something like this: <h ...

Implement Offcanvas feature with Bootstrap 3 Navbar set to Fixed Top position

I am in the process of creating a website that will feature a large menu. However, I am not a fan of the collapsed menu that comes with BS3. Instead, I would like to implement a drawer or off-canvas menu similar to the one showcased in BS3's offcanvas ...

Struggling to override a css element in a responsive design

Here is a Link that I am having trouble with. Within my CSS, I have an element named tbox. It functions as an inline box with a width set at 100%. On the homepage, it adjusts its width perfectly based on its parent and is fully responsive. However, when na ...

What changes do I need to make to ensure my HTML/jQuery page is optimized for display on an Android mobile

After searching online, I noticed that many resources recommend using "", but unfortunately, it's not yielding the desired results in my specific case. A friend suggested utilizing jquery mobile for my website development, but I believe there must be ...

CSS swapping versus CSS altering

Looking to make changes to the CSS of a page, there are two methods that come to mind: Option 1: Utilize the Jquery .css function to modify every tag in the HTML. For instance: $("body").css("background : red") Alternatively, you can disable the current ...

What is the best way to have gulp monitor my sass file updates and generate a single css file?

I'm currently working on a project using ASP.NET MVC 5 framework and Visual Studio 2013. In order to automate the process of compiling my sass files and publishing them into a bundle.css file, I decided to utilize gulp. Here are the steps I took: I ...

What to do when the image-sprite is too large for the container and needs to be resized to fit within a smaller

Is there a way to resize the sprite image to fit the container without using the tag? The sprite image dimensions are 562px (x5) width x 562px height main-desktop.png .container_outer{ height:200px; width:100%; } .chrome-part, .ie-part, .firefox- ...

Changing the color of an Angular <div> element with scripting

I am currently working on an Angular 6 project and I need to change the colors of a div tag from a script after a click function. However, I also need to change it back to transparent. When I click on the "Inheritance" option, the background color of the ...

Overusing For Loops for Cloning in JavaScript

REVISED: (I have pinpointed the issue previously discussed in the comments) this is the code I am working with: <script type="text/javascript"> for(var i=0; i<5; i++){ $(".image-wrap").clone().appendTo(".container").attr(&apo ...

What is the best way to pass a value to a modal and access it within the modal's component in Angular 8?

How can I trigger the quickViewModal to open and send an ID to be read in the modal component? Seeking assistance from anyone who can help. Below is the HTML code where the modal is being called: <div class="icon swipe-to-top" data-toggle="modal" da ...

React: Animate with CSS

How can I make sure that every time a new user is prepended, the first div has a CSS animation? Currently, my code only works for the first prepend and the animation does not trigger on subsequent ones. const [userList, setUserList] = useState<any> ...

Storing and retrieving files with HTML5 local storage

Is there a way for me to utilize HTML5 local storage in order to store a small executable file and subsequently offer it for download via a button click? ...

set available date with angular bootstrap datetimepicker

Currently, I am utilizing an angular bootstrap datetimepicker plugin that can be found at https://github.com/dalelotts/angular-bootstrap-datetimepicker. My goal is to configure the calendar so that only dates within the range of today and seven days in t ...

Clearing Up CSS Height Definitions

Based on my observations from other posts, it seems that to establish the height of an element in percentages or pixels, etc., the parent element's height also needs to be explicitly defined. This implies that the height settings must be specified all ...

SleekScroll, SafariAssist, and Adaptive Navigation

I have a few queries regarding this side here Is there a way to implement smooth scrolling? I've experimented with different options, but removing the .slim from jquery breaks the dropdown functionality. How can I resolve this issue? I encounter ...

Vibrant Reverberation of Color

When creating a table connected to a MySQL database, I encountered an issue with changing the text color inside the rows. How can I display the text in white within the table? I attempted to use <style = color #34242, but it didn't produce the des ...

Mac users may experience lag when using Javascript parallax effects

I created a parallax page where the background image changes using JavaScript translateY(- ... px)' similar to what you see on the firewatch website. On Windows, the parallax effect works smoothly. However, on macOS it is smooth only in Safari. All ...

What is the best way to ensure that the radius of the circle adjusts according to the canvas element in

I've successfully drawn a circle on a canvas element, but now I need to make it responsive. How can I achieve this? I want the radius of the circle to change by a certain amount when the browser width or height changes. How do I calculate this changi ...

arbitrary arrangement of elements within container element

I need assistance with positioning random elements inside a DIV. These elements have varying LEFT and TOP positions within the parent element <div class="main"></div>. How can I mathematically calculate and set these positions using JavaScript/ ...

Is there a way to decrease the speed of a text when hovering over it?

Is there a way to create a button that displays text before another text only on hover, with a delay? I've managed to achieve the effect but can't figure out how to slow it down. For example, notice how quickly the word "let's" appears when ...