positionによる段組みレイアウト@10月24日
position
static
●基準値。特に配置方法を指定しない。
●この値のときには、top、bottom、left、rightは適用されない。
relative
●ブラウザの左上が基点となる。
●top.leftで指定する。
absolute
●親ボックスにpositionのstatic以外の値が指定されている場合には、親ボックスの左上が基準位置。
●static以外の値が指定されていない場合には、ウィンドウ全体の左上が基準位置。
fixed
●絶対位置への配置となるのはabsoluteと同じだが、スクロールしても位置が固定されたままとなる。
外側がrelative、内側がabsoluteが基本!
z-index
z-index:1000 ←上
z-index:1 ←下
先の読まれた方が下に配置されるので、これで上下関係を調整。
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.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" media="screen,print"> #container{ width: 780px; height: auto; margin: 0 auto; position: relative; background-color: #999; overflow: auto; } #header { height: 80px; margin: 10px; background-color: #06265F; } #header_inner { font-size: 0.8em; position: absolute; right: 20px; top: 40px; } #header_inner li { display: inline; margin: 0 0 0 10px; } #header_inner li a { color: #fff; text-decoration: none; } #wrapper { height: 310px; margin: 10px; position: relative; background-color: #3F67BF; } #content { position: absolute; top: 10px; left: 10px; width: 530px; height: 290px; background-color: #B4ECF4; } #saidebar { position: absolute; top: 10px; left: 550px; width: 200px; height: 290px; background-color: #55FFEA; } </style> </head> <body> <div id="container"> <div id="header"> <div id="header_inner"> <lu> <li><a href="#">このサイトについて</a></li> <li><a href="#">お問い合わせ</a></li> <li><a href="#">サイトマップ</a></li> </ul> </div> </div> <div id="wrapper"> <div id="content"> <br /><br /><br /><br /><br /><br /><br /><br /><br /> </div> <div id="saidebar"> <br /><br /><br /><br /><br /><br /><br /><br /><br /> </div> </div> </div> </body> </html>