在大型桌面中,四个div应该出现在一行中。在中等大小中,应该出现三个div,在小型设备中,两个div和移动设备中只有一个潜水应该出现在一行中。我实现了它。但是我需要所有的div都有边界,并且在两个连续的div之间应该有一个px间隙。
我添加了边框它工作正常,当我向div添加边距1px然后在大型桌面中第四个div将移动到下一行。 我的Html代码是 -
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Basic Bootstrap Template</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="BootstrapFiles/css/bootstrap.min.css">
<style type="text/css">
.bgcolor{
background-color:orange;
}
.divCustom{
border:solid 1px black;
}
</style>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-sm-6 col-md-4 col-lg-3 divCustom">
Personal Information
<div class="row">
<div class="col-xs-12">
<label class="control-label" for="txtName">Name</label>
<input id="txtName" class="form-control" />
</div>
</div>
<div class="row">
<div class="col-xs-12">
<label class="control-label" for="txtDepartment">Department</label>
<input id="txtDepartment" class="form-control" />
</div>
</div>
</div>
<div class="col-sm-6 col-md-4 col-lg-3 divCustom">
Physical Information
<div class="row">
<div class="col-xs-12">
<label class="control-label" for="txtName">Name</label>
<input id="txtName" class="form-control" />
</div>
</div>
<div class="row">
<div class="col-xs-12">
<label class="control-label" for="txtDepartment">Department</label>
<input id="txtDepartment" class="form-control" />
</div>
</div>
</div>
<div class="col-sm-6 col-md-4 col-lg-3 divCustom">
Extra Information
<div class="row">
<div class="col-xs-12">
<label class="control-label" for="txtName">Name</label>
<input id="txtName" class="form-control" />
</div>
</div>
<div class="row">
<div class="col-xs-12">
<label class="control-label" for="txtDepartment">Department</label>
<input id="txtDepartment" class="form-control" />
</div>
</div>
</div>
<div class="col-sm-6 col-md-4 col-lg-3 divCustom">
Other Information
<div class="row">
<div class="col-xs-12">
<label class="control-label" for="txtName">Name</label>
<input id="txtName" class="form-control" />
</div>
</div>
<div class="row">
<div class="col-xs-12">
<label class="control-label" for="txtDepartment">Department</label>
<input id="txtDepartment" class="form-control" />
</div>
</div>
</div>
</div>
</div>
<script src="BootstrapFiles/js/jquery.min.js"></script>
<script src="BootstrapFiles/js/bootstrap.min.js"></script>
</body>
</html>
答案 0 :(得分:7)
您不应直接对网格元素应用边距,边框等。这需要对Bootsrap的CSS中的大小调整进行相应的调整,这使得维护和更新更具挑战性。
而是将样式应用于网格容器内的元素。
http://jsfiddle.net/isherwood/gQere/
.bordered {
border:solid 1px black;
}
<div class="col-sm-6 col-md-4 col-lg-3 divCustom">
<div class="bordered">Personal Information
<div class="row">
<div class="col-xs-12">
<label class="control-label" for="txtName">Name</label>
<input id="txtName" class="form-control" />
</div>
...
根据您的偏好调整.bordered
上的边距。您可以使用负边距延伸到网格元素之外并获得您提到的1px间隙(或者可能是2px,因为它更容易)。