我的位置:使用flexbox时,粘性元素不粘性

我的位置:使用flexbox时,粘性元素不粘性,第1张

我的位置:使用flexbox时,粘性元素不粘性

由于flex box元素默认为

stretch
,因此所有元素都具有相同的高度,无法滚动

将添加

align-self: flex-start
到粘性元素的高度设置为auto,可以滚动并固定它。

当前,所有主流浏览器均支持此功能,但Safari仍在

-webkit-
前缀后面,并且除Firefox以外的其他浏览器在
position:sticky
表方面存在一些问题。

.flexbox-wrapper {  display: flex;  overflow: auto;  height: 200px;          }.regular {  background-color: blue;   height: 600px;          }.sticky {  position: -webkit-sticky;   position: sticky;  top: 0;  align-self: flex-start;   background-color: red;  }<div >  <div >    This is the regular box  </div>  <div >    This is the sticky box  </div></div>


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5042311.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-11-15
下一篇2022-11-15

发表评论

登录后才能评论

评论列表(0条)

    保存