The grid display's columns are hidden on smaller screen devices

I am working on a webpage with the following HTML structure:

.main {
  display: grid;
  grid-template-columns: 1fr 2fr;
}

.main>div {
  height: 200px;
}

.main>div:first-child {
  border: solid 3px red;
}

.main>div:last-child {
  border: solid 3px blue;
}
<div class="main">
  <div>
    contents 1
  </div>
  <div>
    contents 2
  </div>
</div>

https://i.sstatic.net/MpATU.png I am pleased with the current layout where the blue div is twice the width of the red div. However, I am facing an issue when the screen size is reduced to less than 246px, causing the blue div to hide under the browser edge :

https://i.sstatic.net/VSAAz.png

How can I ensure that the ratio between the two divs remains consistent even on smaller screen sizes?

Update: I have removed the font-size property but the problem persists.

Answer №1

To ensure proper display on mobile devices, it is important to include the viewport meta tag in your HTML code and adjust the initial margin and padding for the html and body tags.

Here is an example of how the final code should look like:

<!DOCTYPE html>
<html>

<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <style>
        html,
        body {
            margin: 0;
            padding: 0;
        }

        .main {
            display: grid;
            grid-template-columns: 1fr 2fr;
        }

        .main>div {
            height: 200px;
        }

        .main>div:first-child {
            border: solid 3px red;
        }

        .main>div:last-child {
            border: solid 3px blue;
        }
    </style>
</head>

<body>
    <div class="main">
        <div>
            contents 1
        </div>
        <div>
            contents 2
        </div>
    </div>
</body>

</html>

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

Achieving a smooth sliding motion with the help of jQuery animation

Here is the code snippet: In HTML: <div> <div id="div1">12345</div> <div id="div2">67890</div> <div id="div3"><a href="#" id="slide">abcde</a></div> <div id="pad" style="display:non ...

Automating item selection using Selenium in Python

Currently, I am in the process of developing a software program to automate web database management. However, I have encountered an issue while trying to manipulate a table where I need to arrange the items based on one of the columns by clicking on the co ...

An issue with JSPDF arises when used on mobile devices

Currently, I am working on a project to create a responsive web application, which involves utilizing JSPDF for generating PDF reports directly from HTML. For a demonstration of the functionality, you can check out this Demo. Unfortunately, when trying t ...

Ways to verify the input text for content without activating the submit action using only JavaScript

I'm working on creating a unique input effect where the label moves up 100px when the input is focused, and then remains at the top when the user enters a value. If the input is empty and the user clicks outside, the label will return to its original ...

Connecting external websites in XAMPP: A beginner's guide

While using Xampp, I encountered an issue when attempting to access any online website with the following code: <a href="www.xyz.com">Click</a> Instead of directing me to www.xyz.com, it displays this in the URL field: localhost/www.xyz.com ...

Progress Circles on Canvas in FireFox

Currently, I am experimenting with this codepen demo that utilizes canvas to generate progress circles: The functionality functions perfectly in Chrome and Safari; however, it only displays black circles in FireFox. My knowledge of canvas is limited, so I ...

Discovering an <a> element with an href attribute containing two specified strings

Here's what I have: $("a[href*='string1' && 'string2']") Unfortunately, this code didn't work for me. I also attempted: $("a:contains('string1' && 'string2')") The second one only return ...

Fixed header similar to Twitter's design

Looking to create a fixed header similar to Twitter/Facebook that sticks to the top of the page? I tried implementing this solution, but encountered design issues when resizing my browser. <div id="head"> <div id="logo"> <a href= ...

Rotating through elements in timed intervals

After exploring various examples of how to show/hide divs with a JavaScript timeout, I am still unable to resolve my specific issue. I currently have six divs that I want to cycle through sequentially every 10 seconds, starting with div #one. Although my ...

Using jQuery does not automatically pre-check multiple checkboxes. This issue may arise when using PHP and AJAX together

I'm attempting to dynamically check multiple checkboxes based on previous entries from a MySQL database. I have the data stored in a variable: var = ObjektLevHur; The potential data values are: frittlev, frittfabrik, or mont. When I make my first sele ...

Hide a header and bring it back after a 2-second delay

I REPLIED BELOW Is there a way to make the header of my webpage fade out when scrolled and then be hidden using style.display? Here's what I have so far: <script type="text/javascript> function Scroll() { var head = document.getEl ...

Notification continuously appears when clicking outside of Chrome

I have implemented the use of onblur on a text box to display an alert. However, I encountered an issue where if I click outside my Chrome browser after entering text in the text box and then click on the Chrome browser button in the task bar, the alert ap ...

Creating a dynamic rectangular design with a taller height than width, featuring perfectly centered content

My website needs a responsive rectangle where I can easily adjust the height and width. However, when I try to rotate the rectangle, the content also rotates 90 degrees. Can anyone help me with this issue? Thank you in advance for any assistance. Snippet ...

Achieving vertical centering in Bootstrap using the "table-cell" method

I'm trying to center a div both vertically and horizontally using the "table-cell" method without specifying a specific height. However, it's not working as expected. Why isn't this method working for me? Here is the code I am using: < ...

Relative positioning can break the background-clip attribute for text elements

I am experimenting with using background-clip: text on an element that contains some child <p> elements. I wanted to enhance the design by adding some absolutely positioned :after elements to the <p> tags, covering up the text for animation eff ...

Resizing SVG to specify width in pixels and automatically adjust height

I'm having trouble understanding how SVG works. Can someone explain where my mistake is? Here's an example of my inline SVG code: <div style="width:1000px; height:auto; background-color:blue;"> <svg class="_image"><use xlink ...

Learn how to dynamically apply a CSS attribute for a set period of time using jQuery and automatically revert it back to its original state after 2 seconds

Is there a way to apply a CSS attribute to a specific element (like a div) for only 2 seconds? Here is what I have tried so far: HTML: <div class="custom-div">bar</div> <input class="button" type="button" value="press me" /> JQuery: $ ...

Generate several invoices with just a single click using TypeScript

I'm interested in efficiently printing multiple custom HTML invoices with just one click, similar to this example: https://i.sstatic.net/hAQgv.png Although I attempted to achieve this functionality using the following method, it appears to be incorr ...

Eliminating duplicate data submissions with jQuery Ajax

Encountering an issue with my jQuery AJAX submission process. JavaScript: $('#myform').submit(function () { if (validateEvenInputs()) { $('#btnevent').attr('disabled', 'disabled'); function ...

Removing the final BR elements from a div using jQuery

Does anyone know how to remove only the last <BR> tag within a div using jQuery? The code I tried ends up removing all <BR> tags in the div instead of just the last one. HTML Code <div class="topic"> Lorem ipsum dolor sit amet, consect ...