Issue
I am trying to create a Bootstrap container that has two columns. On larger screens, the columns should be side by side horizontally, on smaller screens they should be stacked vertically. There should be a 1px border around the columns with rounded corners. As per the mockup images below:
How can I do this? Notice where the columns touch on both large and small screens, the borders are still only a total of 1px and are not rounded.
Here's where I'm at right now:
.custom-left-column {
border: 1px solid #ccc;
background-color: #fff;
padding: 15px;
border-top-left-radius: 10px;
border-bottom-left-radius: 10px;
}
.custom-right-column {
border: 1px solid #ccc;
background-color: #e9ecef;
padding: 15px;
border-top-right-radius: 10px;
border-bottom-right-radius: 10px;
}
<link
rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/5.0.0/css/bootstrap.min.css"
/>
<div class="container-fluid mx-auto" style="max-width: 70%">
<div class="row">
<!-- Left Column-->
<div
class="col-lg-8 d-flex align-items-center mx-auto custom-left-column"
>
<p>Left Column</p>
</div>
<!-- Right Column -->
<div
class="col-lg-4 d-flex align-items-center mx-auto custom-right-column"
>
<p>Right Column</p>
</div>
</div>
</div>
Solution
Try this code:
.custom-left-column, .custom-right-column {
border: 1px solid #ccc;
padding: 15px;
text-align: center;
}
.custom-left-column {
background-color: #fff;
border-top-left-radius: 10px;
border-bottom-left-radius: 10px;
}
.custom-right-column {
background-color: #e9ecef;
border-top-right-radius: 10px;
border-bottom-right-radius: 10px;
}
@media screen and (max-width:768px) {
.custom-left-column {
border-radius: 0;
border-top-left-radius: 10px;
border-top-right-radius: 10px;
}
.custom-right-column {
border-radius: 0;
border-bottom-left-radius: 10px;
border-bottom-right-radius: 10px;
}
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
<div class="row m-2">
<!-- Left Column-->
<div class="col-md-9 align-items-center custom-left-column">
<p>Left Column</p>
</div>
<!-- Right Column -->
<div class="col-md-3 align-items-center custom-right-column">
<p>Right Column</p>
</div>
</div>
Answered By - Nissim Elbaz
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.