我正在尝试为个人应用程序构建一个小型管理仪表板,但我不知道如何确保页面本身现在可以溢出,而是内部的元素可以溢出。
这是我想要开始工作的示例代码:
<body>
<div class="h-screen w-screen bg-teal-100 flex overflow-hidden">
<!-- Toolbar with a fixed width -->
<div class="h-full bg-blue-50" style="width: 100px;">Toolbar</div>
<!-- Container for Sidebar and Content 1, taking up the remaining width -->
<div class="flex-grow h-full bg-orange-50 flex">
<!-- Sidebar with a fixed width -->
<div class="bg-purple-50" style="width: 200px;">Sidebar</div>
<!-- Content 1 taking the remaining space -->
<div class="flex-grow h-full bg-indigo-500 flex flex-col">
<div class="bg-green-50">A</div>
<div class="bg-purple-50">B</div>
<div class="flex-grow bg-teal-200 flex flex-col">
<div class="bg-green-50">Header</div>
<!-- Table div with growing and scrolling capability -->
<div class="flex-grow bg-red-200 overflow-auto">
<!-- Oversized content to demonstrate scrolling -->
<div class="w-[200vw] h-[200vh] text-white">
H (large content here to activate scrolling)
</div>
</div>
<div class="bg-purple-50">Footer</div>
</div>
</div>
</div>
</div>
</body>
我想要实现的是拥有一张桌子:
<div class="w-[200vw] h-[200vh] text-white">
H (large content here to activate scrolling)
</div>
如果表格溢出,我只会得到该表格的滚动条。这让我发疯
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin Dashboard</title>
<style>
body {
margin: 0;
}
</style>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/tailwind.min.css" rel="stylesheet">
</head>
<body>
<div class="h-screen w-screen bg-teal-100 flex overflow-hidden">
<!-- Toolbar with a fixed width -->
<div class="h-full bg-blue-50" style="width: 100px;">Toolbar</div>
<!-- Container for Sidebar and Content 1, taking up the remaining width -->
<div class="flex-grow h-full bg-orange-50 flex">
<!-- Sidebar with a fixed width -->
<div class="bg-purple-50" style="width: 200px;">Sidebar</div>
<!-- Content 1 taking the remaining space -->
<div class="flex-grow h-full bg-indigo-500 flex flex-col">
<div class="bg-green-50">A</div>
<div class="bg-purple-50">B</div>
<div class="flex-grow bg-teal-200 flex flex-col">
<div class="bg-green-50">Header</div>
<!-- Table div with growing and scrolling capability -->
<div class="flex-grow bg-red-200 overflow-auto">
<!-- Oversized content to demonstrate scrolling -->
<div class="w-[200vw] h-[200vh] text-white">
H (large content here to activate scrolling)
</div>
</div>
<div class="bg-purple-50">Footer</div>
</div>
</div>
</div>
</div>
</body>
</html>
h-screen w-screen
确保容器占据视口的完整高度和宽度。overflow-hidden
会阻止页面本身滚动。flex-grow
类确保剩余空间由内容区域使用,flex
确保布局保持灵活。overflow-auto
)的div上的w-[200vw] h-[200vh]
确保当内容溢出时只有该div会滚动。