/ /私の位置:flexboxを使用している場合、粘着性のある要素は粘着性ではありません - css、flexbox、sticky

私の位置:flexboxを使用しているときは、粘着要素は粘着性ではありません - css、flexbox、sticky

私はちょっとこれについていたし、これを共有していると思った position: sticky +フレックスボックスの問題:

私のスティッキーdivは、私がフレックスボックスコンテナに自分のビューを切り替えるまでうまくいきました。そして、flexボックスの親にラップされたときに、突然、スティッキーがスティッキーにならなくなりました。

.flexbox-wrapper {
display: flex;
height: 600px;
}
.regular {
background-color: blue;
}
.sticky {
position: -webkit-sticky;
position: sticky;
top: 0;
background-color: red;
}
<div class="flexbox-wrapper">
<div class="regular">
This is the regular box
</div>
<div class="sticky">
This is the sticky box
</div>
</div>

問題を示すJSFiddle

回答:

回答№1の場合は37

フレックスボックス要素のデフォルトは stretchすべての要素は同じ高さであり、スクロールすることはできません。

追加する align-self: flex-start スティッキーエレメ​​ントにオートを設定してスクロールを許可し、固定します。

現在のところ、これは サポートされる SafariとEdgeで

.flexbox-wrapper {
display: flex;
overflow: auto;
height: 200px;          /* Not necessary -- for example only */
}
.regular {
background-color: blue; /* Not necessary -- for example only */
height: 600px;          /* Not necessary -- for example only */
}
.sticky {
position: -webkit-sticky;
position: sticky;
top: 0;
align-self: flex-start; /* <-- this is the fix */
background-color: red;  /* Not necessary -- for example only */
}
<div class="flexbox-wrapper">
<div class="regular">
This is the regular box
</div>
<div class="sticky">
This is the sticky box
</div>
</div>

ソリューションを示すJSFiddle