Part3 - 2カラムページ(CSS )

Part3 - 2カラムページ(CSS

  • テキストとは別のワークフローで記述してみる

CSSはresetも含めて1ファイルで記述
  • 読み込みファイル数を少なくする
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<title>【コーディング練習】FARM CAPYZOU</title>
<link rel="stylesheet" href="css/style.css">
</head>
reset CSS
@charset "URF-8";

/* --------------------------------------
  reset
-------------------------------------- */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
ul, li {
  list-style: none;
}
a {
  color: inherit;
  text-decoration: none;
}
img {
  max-width: 100%;
  vertical-align: bottom;
}
body
  • bodyには、文字設定の基準を記述します
  • 背景画像を全面に敷き詰めます
  • bodyのline-heightは、「1.0」で進めるか「1.7」で進めるかの判断が必要です(今回は、1.0に設定します。)
/* --------------------------------------
  body
-------------------------------------- */
body {
  background-image: url(../img/bg.png);
  color: #333;
  font-size: 16px;
  font-family: 
    "Helvetica Neue",
    Arial,
    "Hiragino Kaku Gothic ProN",
    "Hiragino Sans",
    Meiryo,
    sans-serif;
  line-height: 1.0;
}
header部
  • ロゴを中央に配置
    1. header部全体に「text-align: center;」で、nav内のliも同時に中央揃えにする
    2. 幅「320px」指定をして、marginのautoを指定する
/* --------------------------------------
  header
-------------------------------------- */
.header {
  padding: 30px 0 10px;
  text-align: center;
}
  .header h1 > img {
    width: 320px;
    margin-bottom: 30px;
  }
  • ulは、flex-container
  • liは、flex-item
/* --------------------------------------
  nav
-------------------------------------- */
.gnav ul {
  display: flex;
  justify-content: center;
  border-top: 2px solid #7c5d48;
  border-bottom: 2px solid #7c5d48;
}
  .gnav li {
    font-size: 22px;
    font-weight: bold;
  }
  .gnav a {
    display: block;
    padding: 14px 20px;
    color: #7c5d48;
  }
  .gnav a:hover {
    text-decoration: underline double;
  }
layout
  • mainとasideを囲む外枠を指定する「.container」
  • 横並びのレイアウト指定は、「grid」「flex」の2種類のうちどちらかで指定します
    1. flex」は、幅指定を前提に設定します
/* --------------------------------------
  layout
-------------------------------------- */
.container {
  display: flex;
  justify-content: space-between;
  width: 960px;
  margin: 0 auto;
}
main部
/* ------------------------------------
  main
------------------------------------ */
.main-content {
  width: 650px;
  padding: 30px;
  background-color: #fff;
  border-radius: 20px;
  box-shadow: 0 0 6px #ccc;
}
.main-content h2 {
  margin-bottom: 10px;
  font-size: 34px;
  text-align: center;
  line-height: 1.2;
}
.postdate {
  margin-bottom: 30px;
  text-align: center;
}
  .datetime {
    display: inline-block;
    padding: 13px 25px 12px 20px;
    background-color: #79b25e;
    border-radius: 0 0 22px 22px;
    font-size: 18px;
    font-weight: 700;
    color: #fff;
  }
.eyecatch {
  margin-bottom: 30px;
}
.main-content h3 {
  margin-bottom: 16px;
  padding: 20px 10px 6px 48px;
  background: url(../img/h2_icon.png) no-repeat left bottom;
  border-bottom: 2px solid #6ab547;
  color: #7c5d48;
  font-size: 28px;
  font-weight: 600;
}
.main-content h3::first-line {
  color: #cb4b1c;
  font-size: 18px;
  line-height: 1.5;
}
.timeline {
  margin-bottom: 20px;
}
  .timeline img {
    margin: 16px 0 8px;
  } 
  .timeline figcaption {
    font-size: 14px;
    text-align: center;
  }
  .timeline p {
    line-height: 1.6;
  }
aside部
/* ------------------------------------
  aside
------------------------------------ */
.sidebar {
  width: 280px;
  padding: 30px;
  background-color: #fff;
  border-radius: 20px;
  box-shadow: 0 0 6px #ccc;
}
.category-nav, .recent-nav {
  margin-bottom: 24px;
  padding: 32px;
  background-color: #fff;
  border-radius: 16px;
  box-shadow: 0 0 8px rgba(0, 0, 0, 0.16);
}
.sidebar h2 {
  margin-bottom: 18px;
  font-size: 22px;
  font-weight: bold;
  color: #7c5d48;
}
.category-nav ul {
  margin-left: 30px;
}
  .category-nav li {
    list-style: disc;
    line-height: 2.0;
  }
.recent-nav li {
  padding: 20px 0 20px;
  border-bottom: 1px dotted #000;
  line-height: 1.5;
}
  .recent-nav li:first-child {
    padding-top: 10px;
  }
.banner {
  text-align: center;
}
footer部
/* --------------------------------------
  footer
-------------------------------------- */
.footer {
  padding: 16px 0 20px;
  background-color: #523f2d;
}
  .footer p {
    color: #fff;
    font-size: 15px;
    text-align: center;
  }