LoginSignup
0
0

More than 1 year has passed since last update.

階層の深いところで画面サイズに合わせてoverflow:scrollさせる

Last updated at Posted at 2021-06-11

固定長ヘッダー付きの領域を階層構造にして内側の窓でスクロールしたい

<div class="outer">
  <div class="header">aaa</div>
  <div class="content">
    <div class="inner-outer">
      <div class="inner-header">aaa</div>
      <div class="inner-content">
bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb<br>bbb
      </div>
    </div>
  </div>
</div>

header、inner-headerのheightは固定長
inner-contentの大きさをウィンドウの残りの高さでスクロールさせたい

html {
  width:100%;
  height:100%;

  body {
    width:100%;
    height:100%;
    margin: 0;

    .outer {
      display: flex;
      flex-direction: column;
      height:100%;

      .header {
        flex-grow: 0;
      }

      .content {
        flex-grow: 1;
        overflow-y: hidden;

        .inner-outer {
          display: flex;
          flex-direction: column;
          height: 100%;

          .inner-header {
            flex-grow: 0;
          }

          .inner-content {
            flex-grow: 1;
            overflow-y: scroll;
          }
        }
      }
    }
  }
}

flex-grow と overflow: hidden; を使うとうまくいく。

0
0
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
0
0