如何修复网格内的填充?

How to fix the padding inside the grid?

我创建了两个网格并设置了它们的背景图片。网格内的 h3 标题未正确放置。标题“Biryani”和网格底部之间有一个小间隙。我试图删除所有填充,但标题没有正确位于网格底部。请参阅此处的图片并找到下面的代码。

.all-recipes-grid {
  display: grid;
  grid-template-columns: 50vw 50vw;
  padding-top: 10px;
  padding-left: 20px;
  column-gap: 40px;
}

.recipe {
  padding: 20px 0px 0px 0px;
  font-size: 5px;
  border: 1px solid black;
  height: 400px;
  width: 600px;
  display: flex;
  align-items: flex-end;
  text-align: left;
}

.recipe h3 {
  background-color: rgb(230, 230, 230);
  width: 50vw;
  padding-left: 20px;
  height: 100px;
}

.biryani {
  background-image: url('https://images.unsplash.com/photo-1589302168068-964664d93dc0?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8MXx8YmlyeWFuaXxlbnwwfHwwfHw%3D&auto=format&fit=crop&w=500&q=60');
  background-size: cover;
  background-position: center;
}
<!DOCTYPE html>
<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">
  <link rel="stylesheet" href="index.css">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>

  <title>Recipes Website</title>
</head>

<body>
  <div id="nav-bar">
    <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
      <div class="container-fluid">
        <a class="navbar-brand" href="#">Mustaf Recipe</a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
              </button>
        <div class="collapse navbar-collapse" id="navbarSupportedContent">
          <ul class="navbar-nav me-auto mb-2 mb-lg-0">
            <li class="nav-item">
              <a class="nav-link active" aria-current="page" href="/odin-recipes/index.html">Home</a>
            </li>
            <li class="nav-item">
              <a class="nav-link" href="#">Recipes</a>
            </li>
            <li class="nav-item dropdown">
              <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
                      Trending
                    </a>
              <ul class="dropdown-menu" aria-labelledby="navbarDropdown">
                <li><a class="dropdown-item" href="/odin-recipes/recipes/beef-karahi.html">Beef Karahi</a></li>
                <li><a class="dropdown-item" href="/odin-recipes/recipes/mutton-karahi.html">Mutton Karahi</a></li>
                <li><a class="dropdown-item" href="/odin-recipes/recipes/nihari.html">Nihari</a></li>
                <li><a class="dropdown-item" href="/odin-recipes/recipes/pulao.html">Pulao</a></li>
                <li><a class="dropdown-item" href="/odin-recipes/recipes/biryani.html">Biryani</a></li>
              </ul>
            </li>
          </ul>
          <form class="d-flex">
            <input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
            <button class="btn btn-outline-success" type="submit">Search</button>
          </form>
        </div>
      </div>
    </nav>
  </div>
  <div class="all-recipes-grid">
    <div class="biryani recipe">
      <h3>Biryani</h3>
    </div>
    <div class="beef-karahi recipe">
      <h3>Beef Karahi</h3>
    </div>
  </div>
</body>

</html>

默认情况下,标题元素底部有边距。您需要删除 h3.

的边距

试试这个:

.recipe h3 {
   margin-bottom:0;
}