gpt4 book ai didi

reactjs - 为什么位置固定减少了 react 的宽度?

转载 作者:行者123 更新时间:2023-11-28 01:10:09 25 4
gpt4 key购买 nike

为什么当我使用 position:fixed 时我的边栏宽度变小了?这是我的代码 https://codesandbox.io/s/1yr3nlqp74

重现错误的步骤

  1. 新窗口中打开代码(全屏)
  2. 查看使用position :fixed前后的图片

使用位置之前 enter image description here enter image description here

使用位置后此行中的 css 问题

 sideBar__block: {
padding: 20,
position: "fixed",
top: "64px"
},

最佳答案

Position:fixed; 将使 div 成为最大内容 block 的大小,除非应用了宽度。

您可以尝试几个选项。

具有宽度

 sideBar__block: {
padding: 20;
position: fixed;
top: 64px;
width:21%;
}

要使页面灵活,您可以应用leftright 定位

 sideBar__block: {
padding: 20;
position: fixed;
top: 64px;
left:0%;
right:74%;
}

对于更现代的浏览器,您可以使用 position:sticky

 sideBar__block: {
padding: 20;
position: sticky;
top: 64px;
}

这些选项都将允许固定容器随屏幕 flex 。

关于reactjs - 为什么位置固定减少了 react 的宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52147864/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com