在Bootstrap中,Modal对话框底部的空白通常是由Modal的底部固定样式以及可能存在的额外空白元素造成的。如果你没有使用脚注标签(footer),但仍然希望减少底部的空白,可以尝试以下方法:
以下是一个简单的Bootstrap Modal示例,展示了如何应用上述CSS调整:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bootstrap Modal Example</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<style>
.modal-dialog {
min-height: 300px;
}
.modal-body {
flex-grow: 1;
margin-bottom: 0;
padding-bottom: 0;
}
.modal-content {
padding-bottom: 1rem;
}
</style>
</head>
<body>
<!-- Button to trigger modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">
Launch demo modal
</button>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
...
</div>
<!-- No footer here -->
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.5.4/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</body>
</html>
通过上述方法,你应该能够有效地减少Bootstrap Modal对话框底部的空白。
领取专属 10元无门槛券
手把手带您无忧上云