html – CSS Grid doesn't fit horizontally when viewed on mobile-ThrowExceptions

Exception or error:

I’m trying to create a responsive layout where header and footer take around 5% of screen and are fixed. The mid section scrolls depending on number of elements in it. Even though I only mention fr and % values, the element sizes stay static irrespective of screen size changes. In firefox responsive mode (galaxy s9), I see vertical and horizontal scroll bars outside of the container class. Could someone point out what I might be doing wrong ?enter image description here

<html>
<head>
    <meta charset="UTF-8">
    <style>
        .main{
            display:grid;
            grid-template-rows: 2fr 20fr 2fr;
            gap: 2px;
        }
        .header{
            background-color: lightblue
        }
        .container{
            display: grid;
            overflow: auto;
            grid-auto-flow: row;
            grid-auto-rows: 25%;
            gap: 2px;
        }
        .tapbar{
            background-color: pink
        }
        .content{
            background-color:yellowgreen;
        }

    </style>

</head>
<body>
    <div class='main'>
        <div class='header'>header here</div>
        <div class='container'>
            <div class="content">1</div>
            <div class="content">2</div>
            <div class="content">3</div>
            <div class="content">4</div>
            <div class="content">5</div>
        </div>
        <div class='tapbar'>tap bar here</div>
    </div>

</body>

Edit: Besides the selected answer, other mistake I was doing was not having html cover the entire area. Adding this to the style fixed it

html,body,.main{
    height: 100%;
    width: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    }
How to solve:

you just have to add the following meta tags in the head tag of your html page

<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">

Leave a Reply

Your email address will not be published. Required fields are marked *