PCゲーマーのWebデザイン備忘録

PCゲーマーのWebデザイン備忘録。東京都内でWEBデザイナーとして働いています。Webデザインやゲームに関することをブログに書いていきます

【RWD】固定レイアウト演習

以下のテキストを使い、レスポンシブウェブデザインの固定レイアウトの演習を行いました。

スマートフォンサイトのためのHTML5+CSS3 (Web Designing BOOKS)

スマートフォンサイトのためのHTML5+CSS3 (Web Designing BOOKS)


レスポンシブデザインで一番よく使われる固定レイアウトを演習します。
PC以外ではウィンドウを可変させる必要がないため、固定レイアウトで作っても各デバイスでの表示には違いがありません。

演習結果:

960px以上
f:id:game-web-design:20141203140709p:plain

768px~640px
f:id:game-web-design:20141203140731p:plain

639px以下
f:id:game-web-design:20141203140812p:plain


以下はソースです。


今回はブレイクポイントごとに CSS を分けるのではなく、一つの CSS にまとめて書いてみました。


HTML:

<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>固定レイアウト</title>
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="css/style.css">
<link href='http://fonts.googleapis.com/css?family=Maven+Pro:900,400' rel='stylesheet' type='text/css'>
<!--[if lte IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<!--[if lte IE 9]>
<script src="http://ie7-js.googlecode.com/svn/version/2.1(beta4)/IE9.js"></script>
<![endif]-->
</head>

<body>
<div id="container">
<header>
<div id="site">
<h1><img alt="PICKUP STREAM" src="img/logo.png"></h1>
</div>
<nav>
<ul>
<li><a href="#">HOME</a></li>
<li><a href="#">CATEGORY</a></li>
<li><a href="#">ABOUT</a></li>
<li><a href="#">CONTACT</a></li>
</ul>
</nav>
</header>
<div id="headerpost">
<img alt="" src="img/basket.jpg">
<div id="lead">
<h2>買い物に出掛けよう</h2>
<p>隣町に新しくできたショッピングセンターには楽しいお店がたくさんあります。1か所にまとまっているので、たくさん歩き回る必要もなく、楽々とお買い物ができておすすめです。</p>
<p class="date">2014年11月3日</p>
<p class="more"><a href="#">MORE</a></p>
</div>
</div>

<div id="content">
<section class="post">
<a href="#">
<img alt="" src="img/windmill_thumb.jpg">
<h2>風車と風の関係</h2>
<p>風車は風を受けて回転します。このとき、効率よく風を受けるためには、風上に向かって真正面をむかなければなりません…</p>
<p class="date">2014年11月1日</p>
<p class="more_s">MORE</p>
</a>
</section>

<section class="post">
<a href="#">
<img alt="" src="img/leaf_thumb.jpg">
<h2>ツルを伸ばしてどこまでも</h2>
<p>ツル植物は太い木の幹に巻きつき、どんどんとツルを伸ばしていきます。太陽の当たる方向に葉をつけ、枝を伸ばしていく…</p>
<p class="date">2014年10月28日</p>
<p class="more_s">MORE</p>
</a>
</section>

<section class="post">
<a href="#">
<img alt="" src="img/sand_thumb.jpg">
<h2>海岸のデコレーション</h2>
<p>海岸には砂や貝殻しかないように思ってしまいますが、よく見ると草花も生えていることがわかります。ただし、海水や潮風…</p>
<p class="date">2014年10月20日</p>
<p class="more_s">MORE</p>
</a>
</section>

<section class="post">
<a href="#">
<img alt="" src="img/flower_thumb.jpg">
<h2>色とりどりの絨毯</h2>
<p>原生花園では今年も色とりどりの花が咲いています。特に今年は原色の色鮮やかな花がたくさん咲いていますので、週末には…</p>
<p class="date">2014年11月5日</p>
<p class="more_s">MORE</p>
</a>
</section>
</div>

<footer>
<p>PICKUPxSTREAM</p>
<div id="iconmenu">
<ul>
<li><a href="#"><img alt="Twitter" src="img/twitter.png"></a></li>
<li><a href="#"><img alt="Facebook" src="img/facebook.png"></a></li>
<li><a href="#"><img alt="Google Plus" src="img/googleplus.png"></a></li>
<li><a href="#"><img alt="Feed" src="img/rss.png"></a></li>
</ul>
</div>
<div id="submenu">
<ul>
<li><a href="#">Privacy Policy</a></li>
<li><a href="#">Terms of Use</a></li>
<li><a href="#">Contact</a></li>
</ul>
</div>
<p><small>Copyright (c) PICKUP STREAM, all rights reserved.</small></p>
</footer>

</div><!--/#container-->

</body>
</html>

CSS

@charset "utf-8";

/* reset */
html, body, div, span, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
abbr, address, cite, code,
del, dfn, em, img, ins, kbd, q, samp,
small, strong, sub, sup, var,
b, i,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, figcaption, figure, 
footer, header, hgroup, menu, nav, section, summary,
time, mark, audio, video {
  margin:0;
  padding:0;
}
article,aside,details,figcaption,figure,
footer,header,hgroup,menu,nav,section {display:block;}
ul {
  list-style: none;
}
img {
  border: none;
}
a {
  text-decoration: none;
}

/* layout */
body{
  margin: 24px 10px;
  font-size: 85%;
  font-family:"Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
}
#container{
  width: 960px;
  margin: auto;
}
header{
  margin-bottom: 10px;
  overflow: hidden;
}
#site{
  float: left;
}
#site img{
  vertical-align: bottom;
}
nav{
  float: right;
  font-size: 22px;
  font-family: 'Maven Pro', Helvetica, Arial, sans-serif;
  padding-top: 30px;
}
nav li{
  float:left;
}
nav li a{
  display: block;
  float: left;
  margin-left: 20px;
  border-bottom: solid 5px transparent;
  color: #000;
}
nav li a:hover{
  border-bottom-color: #ff1e97;
}
#headerpost{
  margin-bottom:30px;
  background: -webkit-gradient(linear,left top, left bottom, from(#000), to(#888));
  background: -webkit-linear-gradient(#000 0%, #888 100%);
  background: -moz-linear-gradient(#000 0%, #888 100%);
  background: -o-linear-gradient(#000 0%, #888 100%);
  background: -ms-linear-gradient(#000 0%, #888 100%);
  background: linear-gradient(#000 0%, #888 100%);
  overflow: hidden;
}
#headerpost img{
  float: left;
  vertical-align: bottom;
}

#headerpost #lead{
  float: left;
  width: 300px;
  color: #FFF;
  margin-left: 25px;
  overflow: hidden;
}

#headerpost h2{
  margin: 20px 0;
}
#headerpost .more{
  font-size: 18px;
  font-family: 'Maven Pro', Helvetica, Arial, sans-serif;
  text-align: right;
}
#headerpost .more a{
  color: #fff;
  background:url(../img/more.png) no-repeat right center;
  display: block;
  padding: 10px 40px 10px 0;
}

#content{
  margin-bottom: 30px;
  overflow: hidden;
}
.post{
  float: left;
  width: 216px;
  margin: 0 32px 25px 0;
}
.post:last-child{
  margin-right: 0;
}
.post + .post + .post + .post{
  margin-right: 0;
}
.post img{
  width: 216px;
  vertical-align: bottom;
}
.post h2{
  font-size: 16px;
  margin-top: 5px;
}
.post p{
  font: 12px;
  margin: 10px 0;
}
.post .date{
  float: left;
}
.post .more_s{
  float: right;
  color: #fff;
  font-size: 14px;
  font-family: 'Maven Pro', Helvetica, Arial, sans-serif;
  background: #666 url(../img/more_small.png) no-repeat 94% 50%;
  padding: 3px 25px 3px 5px;
}
.post a{
  color: #000;
  display: block;
  overflow: hidden;
}
.post a:hover{
  background: #cfffb2;
}
footer{
  font-family: 'Maven Pro', Helvetica, Arial, sans-serif;
  color :#fff;
  background: #333;
  padding: 10px 10px 20px;
}
footer p{
  float: left;
}
#iconmenu{
  float: right;
}
#iconmenu{
  margin: 0;
  padding: 3px 0 0;
}
#iconmenu li{
  display: inline;
}
#submenu{
  clear: both;
}
#submenu ul{
  margin: 10px 0;
  padding: 3px 0 0;
  font-size: 12px;
}
#submenu li{
  display: inline;
}
#submenu a{
  color:#ff1e97;
  font-weight: bold;
  border-right: solid 1px #fff;
  padding-right: 6px;
  margin-right: 3px;
}
#submenu li:last-child a{
  border: none;
}
#submenu li + li + li a{
  border: none;
}
@media screen and (min-width:640px) and (max-width:979px) {
#container{
  width: 620px;
}
nav li:nth-child(2){
  float: none;
  overflow: hidden;
}
#headerpost{
  position: relative;
}
#headerpost img{
  float: none;
}
#headerpost #lead{
  font: none;
  position: absolute;
  left: 0;
  bottom: 0;
  background-color: rgba(0,0,0,0.7);
  width: auto;
  padding: 10px 20px;
  margin: 0;
}
#headerpost h2{
  font-size: 20px;
  margin: 10px 0 10px 0;
}
#headerpost p{
  font-size: 14px;
  margin-bottom:20px; 
}
#headerpost .date{
  float: left;
}
#headerpost .more{
  float: right;
  margin: -12px 15px 0px 0;
}
.post{
  width: 300px;
  margin-right: 20px;
}
.post:nth-child(even){
  margin-right: 0;
}
.post img{
  width: 300px;
}
.post h2{
  font-size: 22px;
}
.post p{
  font-size: 16px;
}
.post .more_s{
  font-size: 18px;
}

}

@media screen and (max-width:639px){
#container{
  width: 300px;
}
#site{
  float: none;
}
#site img{
  width: 300px;
}
nav{
  float: none;
  font-size: 14px;
  padding-top: 6px;
}
nav ul li a{
  margin-left: 0;
  margin-right: 10px;
}
#headerpost img{
  float: none;
  width: 300px;
}
#headerpost #lead{
  font: none;
  left: 0;
  bottom: 0;
  background-color: #252525;
  width: auto;
  padding: 10px 10px;
  margin: 0;
}
#headerpost h2{
  font-size: 20px;
  margin: 10px 0 10px 0;
}
#headerpost p{
  font-size: 14px;
  margin-bottom:20px; 
}
#headerpost .date{
  float: left;
}
#headerpost .more{
  float: right;
  margin: -12px 15px 0px 0;
}
.post{
  float: none;
  width: 300px;
  margin-right: 0;
}
.post img{
  width: 300px;
}
.post h2{
  font-size: 22px;
}
.post p{
  font-size: 16px;
}
.post .more_s{
  font-size: 18px;
}
}