使用React实现固定导航栏和可折叠固定侧边栏的页面
P粉356361722
P粉356361722 2023-08-29 08:43:17
[CSS3讨论组]
<p>我正在尝试使用 <strong>React</strong> 和 <strong>chakra-ui</strong> 组件实现一个具有固定导航栏和可折叠固定侧边栏的页面。下面是示例代码。</p> <pre class="brush:php;toolbar:false;">import { Box } from &quot;@chakra-ui/react&quot;; export const App = () =&gt; { return ( &lt;Box display=&quot;flex&quot;&gt; &lt;Box position=&quot;fixed&quot; width=&quot;200px&quot; height=&quot;100%&quot; bg=&quot;red&quot; /&gt; {/* Sidebar */} &lt;Box flex=&quot;1&quot; position=&quot;fixed&quot;&gt; &lt;Box position=&quot;fixed&quot; top=&quot;0&quot; width=&quot;100%&quot; height=&quot;50px&quot; bg=&quot;blue&quot; /&gt; {/* Navbar */} &lt;Box mt=&quot;50px&quot; p=&quot;4&quot;&gt; {/* Rest content */} &lt;/Box&gt; &lt;/Box&gt; &lt;/Box&gt; ); };</pre> <p>但是现在顶部导航栏的宽度始终没有达到我的预期。这是它的当前输出。</p> <p>我想实现以下输出。</p> <p>红色框是侧边栏,蓝色框是顶部导航栏。预计他们两人都将固定在目前的位置上。请就如何实现我的期望提供一些建议。我将非常感激!</p>
P粉356361722
P粉356361722

全部回复(1)
P粉805922437

你可以尝试:

<Box position="fixed" top="0" right="0" width="calc(100vh - 200px)" height="50px" bg="blue" /> {/* Navbar */}

注意 200px 是侧边栏宽度

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号