Home > database >  Why isnt my html and css grid not working?
Why isnt my html and css grid not working?

Time:07-20

<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
        <style>
           
        </style>
    </head>
    <body>
        <div style="
        display: grid; 
        grid-template-columns: 100px, 100px;">
        <div style="background-color: lightblue;">div 1</div>
        <div style="background-color: lightpink;">div 2</div>
        </div>
    </body>
    </html>

I've been trying to make a grid in HTML and CSS and it's not working. Im new to CSS and HTML so please tell me what I did wrong thanks!

CodePudding user response:

You should remove comma in grid-template-columns, write like this:

display: grid;

And

grid-template-columns: 100px 100px;

Also you can write like below and it's better

grid-template-columns: auto auto;

See here

CodePudding user response:

There was just one error you have made in grid-template-columns there must be no comma should be included, so it must look like this grid-template-column:100px 100px;

<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
       
    </style>
</head>
<body>
    <div style="
    display: grid; 
    grid-template-columns: 100px 100px;">
    <div style="background-color: lightblue;">div 1</div>
    <div style="background-color: lightpink;">div 2</div>
    </div>
</body>
</html>

CodePudding user response:

You can use grid-template-columns: auto in this case. Hope that solves you

<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div style="display: grid; grid-template-columns: auto auto auto;">
        <div style="background-color: lightblue;">div 1</div>
        <div style="background-color: lightpink;">div 2</div>
        <div style="background-color: rgb(34, 192, 3);">div 2</div>
    </div>
</body>
</html>

  • Related