css 要素内の上・下で固定

「position:fixed」はウィンドウ内での固定だけど、求めているのは要素内での固定

作成日:2018-01-17, 更新日:2018-01-17

基本

・子要素に「position:sticky;」と位置を指定

<style>
.childWrap {
   position: -webkit-sticky;
   position: sticky;
   top: 0;
}
</style>

<div>
  <div class="childWrap">
     〇〇〇
  </div>
</div>

※top、bottomだけじゃなく、leftやrightもOK。

サンプル

CSSだけで要素内の固定のデモ、サンプル