在此代码中添加网格区域有什么问题?

What is wrong with adding grid area in this code?

由于产品无法像这样调整浏览器大小:

我想让我的网格响应,所以我添加了这样的网格区域:

.grid{
    display: grid;
    grid-template-columns:1fr 1fr 1fr 1fr;
    grid-gap:1em;
    grid-area: 'head head head head'
               'card card card card'                            
               'foot foot foot foot'    ;   

}

但现在页脚变小了,我只有一种产品,而不是正文中应该有的产品:

在这段代码中添加网格区域有什么问题?

或者如果有更好的方法让他们响应是什么?

另外这是网站的整体视图:

 
.header{
    color: saddlebrown;
    width: 100%;
    height: 100px;
    position: fixed;
    background-color: burlywood;
    opacity: 33px;
    top: 0;
    left: 0;
    right: 0;
    margin-top: 0;
    margin-right: 0;
    z-index: 1000;
    grid-area: head;
     


}

body{
    margin-top: 333px;
  display: grid;
  grid-template-rows: auto 1fr auto; 
   
  min-height: 100vh;
  margin-right: 0;
  margin-left: 0;
  margin-bottom: 0;
   
}  
.footer{
  color: white;
  background: sandybrown;
  margin-top: 100px; 
  height: 100px; 
  margin-right: 0;
  width: 100%; 
  grid-area: foot;
}

.card {
  
  max-width: 400px;
    margin: auto ;
  text-align: center;
  font-family: arial;
  border-style: solid;
  border-width: 6px;
  position:  relative;
  grid-area: card ;

   
  
  

}

 
.grid{
      display: grid;
    grid-template-columns:1fr 1fr 1fr 1fr;
    grid-gap:1em;
    grid-area: 'head head head head'
                'card card card card'                           
                'foot foot foot foot'   ;   

}



.card img{

  height: 400px; 
    width: 400px;
  vertical-align: middle;
 
 
}

.price {background-color: #f44336;
    font-size:22px;
    border-radius: 3px;
    position: absolute;
    bottom: 0px;
  right: 0px;
  padding: 3px;




}

.card button {
  border: none;
  color: white;
  background-color: #000;
  position: relative ;
  cursor: pointer;
  width: 100%;
  height: 100px;
  font-size: 44px;
  align-items: center;



  


}

.card button:hover {
  opacity: .5;
  background-color: #330;


}
 

#id{

    background-color: saddlebrown;
    color: white;   
    margin: 0; 
    font-size: 30px;
    height: 310px;


}
 
 
.number{
    width: 50px;
    height: 50px;
    background-color: #330;
    color: yellow;
    border-radius: 50%;
    position: absolute;
    top: -22px;
    right: -22px;
    justify-content: center;
    align-items: center;
    display: flex;
    font-size: 22px;

}

 

@media screen and (max-width: 1864px){
    .card{
        max-width: 300px;
    }
     
    .price{

        font-size:20px;

    }

    .card img{
        height: 300px; 
        width: 300px;

    }
}


@media  screen and (max-width: 1319px){
     
    .grid{
        grid-template-columns:1fr 1fr 1fr ;
    }

}


 
 
{% load static %}
<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet"   href="{% static 'main.css' %}">
    <div class="header">
        <h1 >header</h1>
    </div>
    
</head>
<body style="background-color: #36454F;">

    

    <div class="grid">  
        {% for i in p%} 
                
                    <div class='card'>
                        <div class="number">{{i.Number}}</div>
                        <img src="{{i.image}}"></img>
                        <p id="id">{{i.description}}</p>
                        <a href="{{i.buy}}" target='_blank' rel='noopener noreferrer'>
                            <button><span class="price"> ${{i.price}}</span> buy</button>
                        </a>    




                    </div>

        {%endfor%}
    </div>

    <div class="footer">
        <h1 >&copy All rights reserved</h1>

    </div>   

</body>
</html>

你想设置 grid-area 头和脚在网格之外。

我的建议是从网格中删除 grid-area,并仅将 grid-template 与媒体查询一起使用,或者您可以使用 flex-wrap.

添加 display flex