I’m trying to implement a page with fixed navbar and collapsible fixed sidebar, using React and chakra-ui component. Below are the example code.
import { Box } from "@chakra-ui/react";
export const App = () => {
return (
<Box display="flex">
<Box position="fixed" width="200px" height="100%" bg="red" /> {/* Sidebar */}
<Box flex="1" position="fixed">
<Box position="fixed" top="0" width="100%" height="50px" bg="blue" /> {/* Navbar */}
<Box mt="50px" p="4">
{/* Rest content */}
</Box>
</Box>
</Box>
);
};
But now the width of the top navbar never meets my expectations. This is its current output.
I want to achieve the following output.
The red box is the sidebar and the blue box is the top navbar. Both of them are expected to be fixed on their current position. Please offer some advice on how to achieve my expectation. I will appreciate it a lot!
2
Answers
you can try:
notice that 200px is the sidebar width
You can use this layout component. it have header and collapsible sider.
also you can checkout more with chakra-ui at chakra-sidebar-layout-components