I'm using Bootstrap 4.1. I'd like to have a grid of cells (Box A-E) with some spacing in between them. If I set padding on each column, I also get padding on the left and right side that breaks alignment with other elements; I would like Box A and Box D to align with the left edge of Top Box, for example.
The documentation talks about using a negative margin to offset this but I couldn't figure out where to put it.
The set of boxes is dynamic (there could be dozens) and I'd like to apply consistent styling to all of them, rather than make modifications to specific boxes.
I also want to avoid making modifications to Top Box, which is a stand-in for many existing UI elements in my real page that cannot easily be changed.
Here's a JSFiddle: https://jsfiddle.net/u5094cjb/2/
body {
margin: 1rem;
}
.box {
border: 1px solid black;
background-color: white;
margin-bottom: 0.1rem;
}
<head>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
</head>
<div class="container">
<!-- ideally don't change this part -->
<div class="row">
<div class="col">
<div class="box">Top Box</div>
</div>
</div>
<!-- change this part only -->
<div class="row">
<div class="col">
<div class="container">
<div class="row">
<div class="col-4 px-1">
<div class="box">Box A</div>
</div>
<div class="col-4 px-1">
<div class="box">Box B</div>
</div>
<div class="col-4 px-1">
<div class="box">Box C</div>
</div>
<div class="col-4 px-1">
<div class="box">Box D</div>
</div>
<div class="col-4 px-1">
<div class="box">Box E</div>
</div>
</div>
</div>
</div>
</div>
</div>
