我有一个非常简单的代码:
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-gH2yIJqKdNHPEq0n4Mqa/HGKIhSkIHeL5AyhkYV8i59U5AR6csBvApHHNl/vI1Bx" crossorigin="anonymous">
<div class="pt-5 bg-info">
<!-- Something -->
</div>
<div class="row pt-4 bg-success">
<!-- Something -->
</div>
但是,作为一个结果(这个特定的代码),我有2个不同宽度的这些块。那么为什么会发生这种情况,如何防止这种情况?
1条答案
按热度按时间6qfn3psc1#
The problem is caused by Bootstrap library's internal
row
class-bs-gutter-x: 1.5rem;
to set the property. If you manually overwrite this property, this behavior will be resolved as you wish. Changing the library's behavior in this way causes different side effects. This is not recommended behavior. That's why I suggest you follow the steps in section "Suggestion".Suggestion
The
pt
class is used to change thepadding-top
property. The different use of thept
class is not relevant to the problem. To responsively place elements horizontally, define child<div>
elements withrow
class within a<div>
element withcontainer
class.References