Chapter06 上部メニューの作成

概要と目標 リスト関連やテーブル関連の
プロパティを学習しよう。

リストに関するプロパティや、テーブルに関するプロパティを学習しましょう。

今回のゴール

RERUN

リストマーカーの種類 list-style-typeプロパティ

list(リスト)-style(スタイル)-type(タイプ)は、リスト項目のマーカの種類を指定するプロパティ。

初期値 値の継承 適用対象
disc する リストアイテム要素
主な値
指定できる値 説明
none なし
disc 黒丸
circle 白丸
square 黒四角
decimal 数字
upper-alpha 大文字のアルファベット
lower-alpha 小文字のアルファベット
upper-roman 大文字のローマ数字
lower-roman 小文字のローマ数字
decimal-leading-zero ゼロ付きの数字
lower-greek 小文字のギリシャ文字
upper-latin 大文字のラテン文字
lower-latin 小文字のラテン文字
hebrew ヘブライ数字
armenian アルメニア数字
georgian グルジア数字
cjk-ideographic 漢数字
hiragana ひらがな
katakana カタカナ
hiragana-iroha ひらがなのいろは
katakana-iroha カタカナのいろは

list-style-typeプロパティを
使ってみよう。

  1. 「css-lessons」 › 「chapter06」 › 「list-style-type」フォルダ内の「index.html」をテキストエディタで開く
  2. HTMLの内容を確認
chapter06/list-style-type/index.html
<h1>リスト関連</h1>

<ul class="list1">
  <li>リスト項目</li>
  <li>リスト項目</li>
  <li>リスト項目</li>
  <li>リスト項目</li>
  <li>リスト項目</li>
</ul>

<hr>

<ol class="list2">
  <li>リスト項目</li>
  <li>リスト項目</li>
  <li>リスト項目</li>
  <li>リスト項目</li>
  <li>リスト項目</li>
</ol>
  1. 「css-lessons」 › 「chapter06」 › 「box」フォルダ内の「style.css」をテキストエディタで開く
  2. class名「list1」と、class名「list2」の、リストのマークを変更
chapter06/list-style-type/style.css
.list1 {
  list-style-type: upper-roman;
}

.list2 {
  list-style-type: hiragana-iroha;
}
  1. 上書き保存
  2. 「css-lessons」 › 「chapter06」› 「list-style-type」フォルダ内の「index.html」をダブルクリック。
  3. リストのマークが変更されたかを確認
ブラウザでの表示例

RERUN


上部メニュー リストをfloatし、
横並びのボタンにする。

上部メニューとは、ページの上部にある横並びのメニューのことで、
一般的にはサイト全体のカテゴリを移動するナビゲーションの役割を担う。

上部メニューを作成してみよう。

  1. 「css-lessons」 › 「chapter06」 › 「navi」フォルダ内の「index.html」をテキストエディタで開く
  2. HTMLの内容を確認
chapter06/navi/index.html
<div id="container">

  <header id="header">
    <h1>上部メニュー</h1>
    <nav id="global-nav">
      <ul>
        <li><a href="#">Home</a></li>
        <li><a href="#">Concept</a></li>
        <li><a href="#">Service</a></li>
        <li><a href="#">About Us</a></li>
        <li><a href="#">Contact</a></li>
      </ul>
    </nav>
  </header>

</div>
<!-- /#container -->
  1. 「css-lessons」 › 「chapter06」 › 「navi」フォルダ内の「style.css」をテキストエディタで開く
  2. id名「global-nav」内を上部メニューにする
chapter06/navi/style.css
* {
  margin: 0;
  padding: 0;

}

body {
  background-color: #eee;
}

#header {
  background-color: #fff;
}

#header h1 {
  padding: 1em;
  font-size: 1.25em;
}

#container {
  width: 960px;
  margin: 0 auto;
}

#global-nav {
  background-color: #333;
}

#global-nav ul {
  overflow: hidden;
  list-style-type: none;
}

#global-nav li {
  float: left;
  width: 20%;
}

#global-nav a {
  display: block;
  padding: 1em 0;
  text-align: center;
  color: #fff;
  text-decoration: none;
  font-size: .875em;
}

#global-nav a:hover {
  background-color: #666;
}

#global-nav li + li a {
  border-left: 1px solid #1a1a1a;
}
  1. 上書き保存
  2. 「css-lessons」 › 「chapter06」› 「navi」フォルダ内の「index.html」をダブルクリック。
  3. 上部メニューに変更されたかを確認
ブラウザでの表示例

RERUN


練習問題 今回の理解度をチェック。

「chapter06」 › 「training」フォルダ内にある「style.css」に、
下記の問題を解いて下さい。

ブラウザでの完成例

RERUN

解答例
chapter06/training/style.css
* {
  font-size: 1em;
  margin: 0;
  padding: 0;
}

body {
  font: 1em/1.5 游明朝, "ヒラギノ明朝 ProN W3", HG明朝E, serif;
  background-image: url(images/bg-washi.png);
  color: #333;
}

/* Centering */
.container {
  width: 960px;
  margin: 0 auto;
}

/* Header */
#header {
  background-color: #fff;
}

.header-title {
  padding: 1em 0;
  font-size: 1.25em;
}

/* ============================
  ここから 上部メニュー
============================ */

/* Global Nav */
#global-nav {
  border-left: 1px solid #ddd;
  border-right: 1px solid #ddd;
}

#global-nav ul {
  overflow: hidden;
  list-style-type: none;
}

#global-nav li {
  width: 16.6666667%;
  float: left;
}

#global-nav a {
  display: block;
  text-align: center;
  text-decoration: none;
  padding: .75em 0;
  font-size: .875em;
  color: #333;
}

#global-nav a:hover {
  color: #999;
}

#global-nav li + li a {
  border-left: 1px solid #ddd;

}

/* ============================
  ここまで 上部メニュー
============================ */


/* Main */
.section {
  padding: 64px 0;
}


/* #Footer */
#footer {
  clear: both;
  background-color: #333;
  padding: 2em 0;
  text-align: right;
}

#footer-nav {
  list-style-type: none;
  margin-bottom: .5em;
}

#footer-nav li {
  display: inline;
}

#footer-nav li + li{
  margin-left: 1em;
}

#footer-nav a {
  color: #ccc;
  font-size: .75em;
}

#footer-nav a:hover {
  color: #999;
  text-decoration: none;
}

#footer-copyright {
  color: #ccc;
  font-size: .75em;
}


/* Heading */
.heading {
  text-align: center;
  font-size: 1.75em;
  margin-bottom: 1em;
}

/* Grid */
.grid {
  overflow: hidden;
  margin: 30px 0;
}

.grid-item {
  float: left;
  width: 300px;
}

.grid-item + .grid-item {
  margin-left: 30px;
}


/* Card */
.card {
  display: block;
  position: relative;
  background-color: #fff;
  padding-top: 212px;
}

.card-body {
  padding: 24px;
}

.card-title {
  margin-bottom: .5em;
  font-size: 1.25em;
}

.card-badge {
  display: inline-block;
  position: absolute;
  top: 200px;
  left: 24px;
  color: #fff;
  background-color: #333;
  z-index: 1;
  font-size: .75em;
  padding: 4px;
}

.card-image {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
}

/* .button */
.button {
  display: block;
  width: 320px;
  margin: 48px auto 0;
  padding: 1em 0;
  text-align: center;
  border: 2px solid #333;
  color: #333;
  text-decoration: none;
  font-weight: bold;
}

.button:hover {
  background-color: #333;
  color: #fff;
}

解答例は全問題のチェックボックスが on になるとご覧いただけます。

まとめ 上部メニューもfloatを使う。

上部メニューを作成する際も、floatを用いてリストを横並びにする。
floatと同時に指定する幅は、「%」を使うと便利。

  • 上部メニューは、li要素を、floatする
  • li要素の幅は「%」で指定すると楽
  • a要素はブロックにし、
    ボタン全体をクリックできるようにする。