positionの基本的な使いかた
absoluteの親要素にrelativeを適用しておくことで自由なレイアウトにしやすくなる。
メニューをpositionを使ってレイアウトする
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="Content-Style-Type" content="text/css" /> <title>positionの確認</title> <style type="text/css"> <!-- * { margin: 0; padding: 0; } ul { list-style-type: none; } body { color: #FFF; font-size: 1.0em; font-family: "ヒラギノ角ゴ Pro W3", "Hiragino Kaku Gothic Pro", "メイリオ", Meiryo, Osaka, "MS Pゴシック", "MS PGothic", sans-serif; background-color: #CCC; } h1 { color: #FFF; font-size: 1.6em; font-family: serif; position:absolute; top:20px; left:20px; } #container { width: 800px; height: auto; margin: 0 auto; padding: 10px; background-color: #FFF; overflow: hidden; } #header { width: auto; height: 100px; margin: 0 0 10px 0; background-color: #A3BED5; position:relative; } #haeder_inner{ position:absolute; bottom:5px; right:10px; } #haeder_inner ul li{ height:1.6em; padding-right:1.0em; display:block; float:left; } --> </style> </head> <body> <div id="container"> <div id="header"> <h1>ここにサイトタイトルが入る</h1> <div id="haeder_inner"> <ul> <li><a href="#">このサイトについて</a></li> <li><a href="#">お問い合わせ</a></li> <li><a href="#">サイトマップ</a></li> </ul> </div> </div> </div> </body> </html>