概要と目標 HTML部分を完成させ、
ベースのCSSを定義する
スマホサイトに必要な viewportメタタグやpicture要素を使って、
HTML部分を完成させましょう。
その後、CSSファイルを作成し、ブラウザのCSSをリセット、
デフォルトスタイルを定義しましょう。
スマホサイトに必要な viewportメタタグやpicture要素を使って、
HTML部分を完成させましょう。
その後、CSSファイルを作成し、ブラウザのCSSをリセット、
デフォルトスタイルを定義しましょう。
スマートフォン、タブレット、PCの3デバイスに対応した、
架空のPhotoギャラリーサイトを制作しましょう。
対応ブラウザは、
IE9 〜。その他のブラウザは最新版のみとする。
一般的なスマートフォンは、デフォルトの状態だと
head要素内に、モバイル端末の画面サイズに合わせる、viewportメタタグを記述。<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Dummy Photo Gallery - 架空の写真ギャラリー</title>
</head>
メインビジュアルは、各デバイスで違う比率の画像にしたい。
picture要素やsource要素を活用して、画像を切り替える。
また高解像度ディスプレイへの対応として、
srcset属性で、
2倍の大きさの画像もセットする。
picture要素、source要素を活用してメインビジュアルを配置<main role="main">
<picture>
<source srcset="images/hero-top-sp.jpg 1x, images/hero-top-sp@2x.jpg 2x" media="(max-width: 767px)">
<source srcset="images/hero-top-tab.jpg 1x, images/hero-top-tab@2x.jpg 2x" media="(max-width: 1023px)">
<img src="images/hero-top-pc.jpg" srcset="images/hero-top-pc.jpg 1x, images/hero-top-pc@2x.jpg 2x" alt="川の横で夕日を見ながら寄り添う男女">
</picture>
<p>The Picture Taken By Me is <em>Beautiful</em></p>
ブラウザが持っているデフォルのスタイル
title要素の下で「common.css」をリンクする<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Dummy Photo Gallery - 架空の写真ギャラリー</title>
<link rel="stylesheet" href="css/common.css">
</head>
@charset "UTF-8";
/*
Base
-----------------------------------------------------*/
/* Reset */
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
main, menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
article, aside, details, figcaption, figure,
footer, header, hgroup, main, menu, nav, section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
文字サイズや、文字の色、書体、背景色など、サイトのベースとなるCSSを
詳細度の低い要素セレクタで指定する
今回は以下のデフォルトスタイルを定義する。
| セレクタ | プロパティ | 値 |
|---|---|---|
html |
ボックスサイズの算出 | ボーダー領域まで |
| ボックスの高さ | 100% |
|
| 文字のサイズ | medium |
|
| 書体 | '游ゴシック', 'Yu Gothic', '游ゴシック体', 'YuGothic', |
|
| 行間 | 1.5 |
|
html要素の全ての子要素と その before、after |
ボックスサイズの算出 | 継承 |
body |
ボックスの高さ | 100% |
| 文字の色 | #263238 |
|
img |
ボックスの最大幅 | 100% |
| ボックスの高さ | 自動 | |
| 縦方向の位置揃え | 下 | |
lang属性の属性値が "en"の全ての要素 |
大文字/小文字の表記 | 全て大文字 |
/* Default Style */
html {
box-sizing: border-box;
height: 100%;
font: medium/1.5 '游ゴシック', 'Yu Gothic', '游ゴシック体', 'YuGothic', 'ヒラギノ角ゴ Pro W3', 'Hiragino Kaku Gothic Pro', 'Meiryo UI', 'メイリオ', Meiryo, sans-serif;
}
html *,
html *:before,
html *:after {
box-sizing: inherit;
}
body {
height: 100%;
color: #263238;
}
img {
max-width: 100%;
height: auto;
vertical-align: bottom;
}
*[lang='en'] {
text-transform: uppercase;
}
今回は、英文の箇所にGoogle FontsのOpen Sans Condensedを使ってみる。
HTMLファイルに以下のlink要素を追加
<link href="https://fonts.googleapis.com/css?family=Open+Sans+Condensed:300,700" rel="stylesheet">
CSSファイルに以下のプロパティと値を追加
font-family: 'Open Sans Condensed', sans-serif;
head要素内に、Webフォント用のlink要素をコピー
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Dummy Photo Gallery - 架空の写真ギャラリー</title>
<link rel="stylesheet" href="css/common.css">
<link href="https://fonts.googleapis.com/css?family=Open+Sans+Condensed:300,700" rel="stylesheet">
</head>
font-familyを*[lang='en']の宣言ブロック内にコピー
*[lang='en'] {
text-transform: uppercase;
font-family: 'Open Sans Condensed', sans-serif;
}