您当前的位置: 首页 >  css

彭世瑜

暂无认证

  • 3浏览

    0关注

    2791博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

css:浏览器滚动条出现时页面宽度会缩窄页面抖动

彭世瑜 发布时间:2022-10-09 18:09:00 ,浏览量:3

解决方式如下

方式一
html {
  overflow-y: scroll;
}

总是显示滚动条,体验不好

方式二
html {
  overflow-y: overlay;
}

兼容性一般 在这里插入图片描述

方式三
html {
  margin-right: calc(100% - 100vw);
}
方式四
html {
  padding-left: calc(100vw - 100%);
}
方式五
scrollbar-gutter: stable;
方式六

解决方案,来自css大佬张鑫旭 的分享


html {
  overflow-y: scroll;
}

:root {
  overflow-y: auto;
  overflow-x: hidden;
}

:root body {
  position: absolute;
}

body {
  width: 100vw;
  overflow: hidden;
}

参考 小tip:CSS vw让overflow:auto页面滚动条出现时不跳动 还有完没完,怎么又来了个 scrollbar-gutter? Prevent scroll-bar from adding-up to the Width of page on Chrome

关注
打赏
1665367115
查看更多评论
立即登录/注册

微信扫码登录

0.0612s