我正在使用Bootstrap卡,我想用2px的边距将它们分开。
尽管如此,当我应用它时(使用Bootstrap的margin类或直接在样式表上),flex-wrap触发器和卡片向下移动一行。
我该如何处理这种行为?
我应该给卡片一个最大宽度吗?
.dark-theme body,
.dark-theme .card {
background-color: #121212;
color: #ffffffa6;
}
.dark-theme section.card {
background-color: #464646;
}
.card {
border-width: 0;
margin: 3px;
}
main {
padding: 100px;
}
h1 {
text-align: center;
}
h2,
.card {
margin-top: 20px;
}
.dark-theme .btn {
background-color: salmon;
border-color: salmon;
}
<head>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
</head>
<div class="highlights row">
<section class="card col-md-6 col-lg-4">
<h3>Where does it come from?</h3>
<p>
orem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s.
</p>
<p>orem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s</p>
<a href="#" class="card__btn btn btn-info">when an unknown</a>
</section>
<section class="card col-md-6 col-lg-4">
<h3>Where does it come from?</h3>
<p>
orem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s.
</p>
<p>
orem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s.
</p>
<a href="#" class="card__btn btn btn-info">
when an unknown
</a>
</section>
<section class="card col-md-6 col-lg-4">
<h3>Where does it come from?</h3>
<p>
orem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s
</p>
<p>orem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s</p>
<a href="#" class="card__btn btn btn-info">
when an unknown
</a>
</section>
2条答案
按热度按时间r8xiu3jd1#
首先也是最重要的,删除Bootstrap类上设置的所有边距。Bootstrap的目的是不需要添加间距/大小,因为它内置在类中。
我对你的结构做了很多修改。主要是尝试按照Bootstrap的建议来构造元素。尽管如此,不要将每张卡片嵌套在节中。相反,将它们嵌套在divs.The
<section>
tag defines a section in a document.中&如果我没有弄错的话,排成一行的三张卡片可以算作一个节。我将所有三张卡片嵌套在一个节中,并将其称为你已经拥有的highlights
类。col
的功能是为某些内容预留空间的方法。因此,在三卡设置中,您应该使用col-4
。最大的列是col-12
,它跨越屏幕的整个宽度。12/4 = 3。然后,您可以使用sm
lg
和md
来获得媒体屏幕上的响应。上面的示例创建了三个相等的-使用预定义的网格类在小型、中型、大型和超大型设备上创建宽度列。这些列在具有row
父级的页面上居中。话虽如此,您的代码没有按预期工作的主要原因是额外的CSS边距,以及
cards
应该嵌套在col
中。最后,如前所述,列大小的误用。我建议你复习一下Bootstrap Grid System,如果你知道Bootstrap,你可以用很少的CSS知识建立一个完全响应的网站。
omvjsjqw2#
在这里,您可以使用Gutters类中的Bootstrap网格系统.
**间距是列内容之间的间隙,由水平填充创建。**我们在每列上设置右填充和左填充,并使用负边距在每行的开始和结束位置偏移,以对齐内容。
您可以根据自己的需要将
g-1
、g-2
、g-3
、g-4
和g-5
排成一行使用。