Need help aligning three Boostrap 5 grids:
- Header outside of accordion
- Overview in accordion header
- Details in accordion body
The accordion header has margins and padding on the left and right, and the collapse icon also occupies some space.
I want the header and details grids to have the same "margins" as the overview grid.
I attempted to add a column with padding like "ps-4 pe-4", but I can only achieve approximate alignment at best.
.colored-bg1 {
background: lightgray
}
.colored-bg2 {
background: lightyellow
}
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="583a37372c2b2c2a3928186d7668766a">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<title>Bootsrap 5 accordion</title>
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="col-4 colored-bg1">Column 1 header</div>
<div class="col-4 colored-bg2">Column 2 header</div>
<div class="col-4 colored-bg1">Column 3 header</div>
</div>
</div>
<div class="accordion" id="accordionExample">
<div class="accordion-item">
<div class="accordion-header" id="headingOne">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne" aria-expanded="false" aria-controls="collapseOne">
<div class="container-fluid">
<div class="row">
<div class="col-4 colored-bg1">Column 1 overview</div>
<div class="col-4 colored-bg2">Column 2 overview</div>
<div class="col-4 colored-bg1">Column 3 overview</div>
</div>
</div>
</button>
</div>
<div id="collapseOne" class="accordion-collapse collapse show" aria-labelledby="headingOne" data-bs-parent="#accordionExample">
<div class="accordion-body">
<div class="container-fluid">
<div class="row">
<div class="col-4 colored-bg1">Column 1 details</div>
<div class="col-4 colored-bg2">Column 2 details</div>
<div class="col-4 colored-bg1">Column 3 details</div>
</div>
<div class="row">
<div class="col-4 colored-bg1">Column 1 details</div>
<div class="col-4 colored-bg2">Column 2 details</div>
<div class="col-4 colored-bg1">Column 3 details</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="680a07071c1b1c1a0918285d4658465a">[email protected]</a>/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
</body>
</html>