在Bootstrap 3/4中将4个矩形框置于屏幕中心,可以使用以下步骤:
<div>
元素来表示每个矩形框。给每个矩形框添加一个特定的类名,例如box
。<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
html, body {
height: 100%;
}
body {
display: flex;
align-items: center;
justify-content: center;
}
.box {
width: 100px;
height: 100px;
background-color: #ccc;
margin: 10px;
}
在上述代码中,body
元素被设置为Flex容器,并使用align-items: center;
和justify-content: center;
将其内容居中显示。box
类定义了矩形框的样式,包括宽度、高度、背景颜色和外边距。
<!DOCTYPE html>
<html>
<head>
<title>Centered Boxes</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.2/dist/css/bootstrap.min.css">
<style>
/* CSS code here */
</style>
</head>
<body>
<!-- HTML code here -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.2/dist/js/bootstrap.min.js"></script>
</body>
</html>
注意:在上述代码中,我们使用了Bootstrap 4的CSS和JavaScript文件,以及自定义的CSS代码。
这样,当你在浏览器中打开该HTML文件时,你将看到4个矩形框被置于屏幕中心。
领取专属 10元无门槛券
手把手带您无忧上云