header部のレイアウト(1)

floatの場合



<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>header(1)</title>
<style type="text/css">
html, body, div, h1, h2 {
	margin: 0;
	padding: 0;
	font-size: 1.0em;
}
body {
  font-family:
  	"ヒラギノ角ゴ Pro W3", 
  	"Hiragino Kaku Gothic Pro", 
  	"メイリオ", 
  	Meiryo, 
  	Osaka, 
  	"MS Pゴシック", 
  	"MS PGothic", 
  	sans-serif;
	background-color: #FFF;
	text-align: center;
}
#container {
		text-align: left;
	margin: 0 auto;
	width: 800px;
	height: auto;
}
#header {
	font-family: 
  	  Georgia, 
  	  "Times New Roman", 
  	  Times, 
  	  serif;
	background-image: url(images/header01.jpg);
	background-position: top left;
	background-repeat: repeat-x;
	width: 800px;
	height: 110px;
	background-color: #0043CF;
	font-weight: bold;
}
h1 {
	font-size: 2.0em;
	color: #FFF;
	padding: 40px 0 0 15px;
}
#header h2 {
	font-size: 0.8em;
	color: #FFC;
	margin: -70px 0 0 0;
	padding: 0 15px 0 0;
	float: right;
}
</style>
</head>
<body>
<div id="container">
<div id="header"> 
<h1 lang="en">Information World</h1>
<h2 lang="en">Technical Information</h2>
</div>
</div>
</body>
</html>

positionの場合

@charset "UTF-8";
html, body, div, h1, h2 {
	margin: 0;
	padding: 0;
	font-size: 1.0em;
}
body {
  font-family:
  	"ヒラギノ角ゴ Pro W3", 
  	"Hiragino Kaku Gothic Pro", 
  	"メイリオ", 
  	Meiryo, 
  	Osaka, 
  	"MS Pゴシック", 
  	"MS PGothic", 
  	sans-serif;
	background-color: #FFF;
	text-align: center;
}
#container {
  position: relative;
	text-align: left;
	margin: 0 auto;
	width: 800px;
	height: auto;
}
#header {
	font-family: 
  	  Georgia, 
  	  "Times New Roman", 
  	  Times, 
  	  serif;
        background-image: url(images/header01.jpg);
	background-position: top left;
	background-repeat: repeat-x;
	width: 800px;
	height: 110px;
	background-color: #0043CF;
	font-weight: bold;
}
h1 {
	font-size: 2.0em;
	color: #FFF;
	padding: 40px 0 0 15px;
}
#header h2 {
  position: absolute;
	font-size: 0.8em;
	color: #FFF;
	top: 6px;
	right: 15px;


  • ヘッダーの文字色が白だったので、背景画像が表示されない場合に文字が見えないと困ると思い、背景色を入れました。
  • 別紙口伝の解答例のようにbodyに背景画像を入れたら、幅が800pxではなく画面いっぱいになってしまったので、headerに背景画像を指定しました。何か間違っているのでしょうか。