我正在尝试创建一个具有两列的 Bootstrap 容器。在较大的屏幕上,列应水平并排,在较小的屏幕上,列应垂直堆叠。列周围应该有一个 1px 的圆角边框。根据下面的模型图片:
我该怎么做?请注意,在大屏幕和小屏幕上,列接触的地方,边框仍然只有 1 像素,并且不是圆角的。
这就是我现在所处的位置:
.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>
试试这个代码:
.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/[email protected]/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>