Web白描

Webデザインの勉強 - 演習

課題03 Recipe Diary

課題03 Recipe Diary 完成例

記述ポイント
  • PC用では、brタグを使わずに「white-space: pre-line;」で見たままの改行を表示する
  • メディアクエリを使って、文字の読みやすさを工夫する
  .copy > p {
    margin-bottom: 80px;
    line-height: 1.7;
    white-space: pre-line;
  }
@media screen and (max-width: 767px) {
  .copy > p {
    padding: 1rem;
  }
}

style.css

@charset "UTF-8";

/* ---------------------------------------
  reset
--------------------------------------- */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
ul {
  list-style: none;
}
a {
  color: inherit;
  text-decoration: none;
}
img {
  max-width: 100%;
  vertical-align: bottom;
}


/* ---------------------------------------
  body
--------------------------------------- */
body {
  background-color: #fff;
  color: #333;
  font-size: 16px;
  font-family: "Noto Sans JP", sans-serif;
  line-height: 1.0;
}


/* ---------------------------------------
  header
--------------------------------------- */
.mainvisual img {
  width: 100%;
  height: 100vh;
  object-fit: cover;
  object-position: center top;
  margin-bottom: 80px;
}


/* ---------------------------------------
  main
--------------------------------------- */
.copy {
  text-align: center;
}
  .copy > h2 {
    margin-bottom: 20px;
    font-size: 32px;
  }
  .copy > p {
    margin-bottom: 80px;
    line-height: 1.7;
    white-space: pre-line;
  }

@media screen and (max-width: 767px) {
  .copy > p {
    padding: 1rem;
  }
}


/* -------------.various -------------- */
.various {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  margin-bottom: 30px;
}
  .various li img {
    width: 100%;
    height: 500px;
    object-fit: cover;
    vertical-align: bottom;
  }

/* --------------.btn ----------------- */
.btn {
  margin-bottom: 80px;
  text-align: center;
}
  .btn > a  {
    display: inline-block;
    padding: 20px 60px;
    border: solid 1px #2b2a27;
    font-size: 0.875rem;
    transition: .3s;
  }
  .btn > a:hover {
    background-color: #ececec;
  }


/* ---------------------------------------
  footer
--------------------------------------- */
.footer {
  font-size: 15px;
  padding: 20px;
  text-align: center;
}
  .sns {
    display: flex;
    justify-content: center;
    margin-bottom: 20px;
  }
  .sns li {
    margin: 0 10px;
  }
  .sns a {
    text-decoration: underline;
  }

index.html

<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>【コーディング練習】Recipe Diary</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" href="img/favicon.ico">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@100..900&display=swap" rel="stylesheet">
<link rel="stylesheet" href="css/style.css">
</head>
<body>

  <!-- header -->
  <header class="header">
    <h1 class="mainvisual"><img src="img/main_visual.webp" alt="日々の料理レシピをまとめている Recipe Diary"></h1>
  </header>
  <!-- /header -->

  <!-- main -->
  <main class="main">

    <section class="copy">
      <h2>Recipe Diary</h2>
      <p>日々の料理レシピをまとめています。
        和食や洋食、中華、お菓子までいろいろな料理レシピをアップしていますので、
        みなさんの献立にお役立てくださいね!</p>
      <ul class="various">
        <li><img src="img/recipe1.webp" alt=""></li>
        <li><img src="img/recipe2.webp" alt=""></li>
        <li><img src="img/recipe3.webp" alt=""></li>
      </ul>
      <p class="btn">
        <a href="#">レシピ一覧を見る</a>
      </p><!-- /.btn -->
    </section><!-- /.copy -->

  </main>
  <!-- /main -->

  <!-- footer -->
  <footer class="footer">
    <ul class="sns">
      <li><a href="#">Instagram</a></li>
      <li><a href="#">Twitter</a></li>
      <li><a href="#">Facebook</a></li>
    </ul>
    <p>&copy; 2024 Recipe Diary</p>
  </footer>
  <!-- /footer -->

</body>
</html>