コンテンツの高さに合わせたいサイドバー
要素を並べるって、普通 float させることが多いと思うんですけど、場合によっては position を使った方がいいことがあります。
そのひとつが、コンテンツの高さにサイドバーの高さも合わせたいって場合です。
HTML
<div id="wrapper">
<div id="content">
left<br />
left<br />
left<br />
left<br />
left<br />
left<br />
left
</div>
<div id="sidebar">right</div>
</div>
CSS
#wrapper {
width: 200px;
margin: 100px;
position: relative;
background: rgb(220, 220, 220);
}
#content {width: 150px;}
#sidebar {
width: 50px;
height: 100%;
position: absolute;
top: 0;
right: 0;
z-index: 1;
background: rgb(180, 180, 180);
}
結果