LoginSignup
6
7

More than 5 years have passed since last update.

コンテンツの高さに合わせたいサイドバー

Posted at

要素を並べるって、普通 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);
}

結果

6
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
7