考虑以下使用 Bootstrap 类的标记:
flex-row
左右放置的两张卡片组成。flex-fill
将卡片安装到可用的垂直空间。.example-large-content
类演示了大量内容。<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bootstrap demo</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
html,
body {
overscroll-behavior: none;
}
.example-large-content {
min-height: 20rem;
}
</style>
</head>
<body class="d-flex flex-column vh-100 bg-light p-5">
<main class="d-flex flex-row flex-fill gap-3 overflow-auto">
<div class="card border-0 rounded-4 flex-fill shadow">
<div class="card-body d-flex flex-column gap-3 overflow-auto">
<div class="example-large-content p-3 rounded-2 bg-danger">
Large content
</div>
<div class="example-large-content p-3 rounded-2 bg-warning">
Large content
</div>
</div>
</div>
<div class="card border-0 rounded-4 flex-fill shadow">
<div class="card-body d-flex flex-column gap-3 overflow-auto">
<div class="example-large-content p-3 rounded-2 bg-danger">
Large content
</div>
<div class="example-large-content p-3 rounded-2 bg-warning">
Large content
</div>
<div class="example-large-content p-3 rounded-2 bg-success">
Large content
</div>
<div class="example-large-content p-3 rounded-2 bg-primary">
Large content
</div>
<div class="example-large-content p-3 rounded-2 bg-info">
Large content
</div>
</div>
</div>
</main>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
问题与同时使用
overflow-auto
和 shadow
有关。阴影的最左、最右和底部被切断,但它们出现在左右卡片之间的间隙中:
有办法解决这个问题吗?
我给了
main
p-5 班级,并将其从 body
中删除。现在 main
可以占据身体的整个宽度,这导致了截断。 body
仍然可以有p-5
,但卡片会变小。
html,
body {
overscroll-behavior: none;
}
.example-large-content {
min-height: 20rem;
}
<head>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="d-flex flex-column vh-100 bg-light">
<main class="d-flex flex-row flex-fill gap-3 overflow-auto p-5">
<div class="card border-0 rounded-4 flex-fill shadow">
<div class="card-body d-flex flex-column gap-3 overflow-auto">
<div class="example-large-content p-3 rounded-2 bg-danger">
Large content
</div>
<div class="example-large-content p-3 rounded-2 bg-warning">
Large content
</div>
</div>
</div>
<div class="card border-0 rounded-4 flex-fill shadow">
<div class="card-body d-flex flex-column gap-3 overflow-auto">
<div class="example-large-content p-3 rounded-2 bg-danger">
Large content
</div>
<div class="example-large-content p-3 rounded-2 bg-warning">
Large content
</div>
<div class="example-large-content p-3 rounded-2 bg-success">
Large content
</div>
<div class="example-large-content p-3 rounded-2 bg-primary">
Large content
</div>
<div class="example-large-content p-3 rounded-2 bg-info">
Large content
</div>
</div>
</div>
</main>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</body>