有没有一种方法来删除填充x从bootstrap列在移动的没有自定义css?

zazmityj  于 2022-12-07  发布在  Bootstrap
关注(0)|答案(3)|浏览(165)

Because Bootstrap gives the possibility of managing styles from classes, I was wondering if I could remove the column padding on mobile only with bootstrap classes.
You can remove padding on larger screens by using for example px-lg-0 but it seems that you can't get the same result with smaller screen.
I tryed px-0 px-lg-1 , px-0 px-lg-2 or px-0 px-lg-3 but none of them have the same padding as the original column padding.
You can see the issue in the snippet below by running it on full screen with a width >= 992px.

.container{
  border:3px solid orange;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.0.2/css/bootstrap.min.css">
  <div class="container">
    <div class="row">
      <div class="col-12 bg-light text-dark">A</div>
      <div class="col-12 bg-dark text-light px-0 px-lg-2">B</div>
      <div class="col-12 bg-light text-dark px-0 px-lg-3">C</div>
  </div>
</div>
vxf3dgd4

vxf3dgd41#

如果您不想走SASS路线,可以在自定义css文件中测试将.container的“--bs-gutt-x”设置为“0”,如下所示(请参见https://codepen.io/sam-miller-the-flexboxer/pen/mdxbQGr中的代码片段)?
第一个

brvekthn

brvekthn2#

Bootstrap提供了gutters类,使您能够更改用于填充的变量的值。
我可以用gx-0 gx-lg-4代替px-0 px-lg-3
第一个

lb3vh1jj

lb3vh1jj3#

此外,除非您需要有带容器间距和不带容器间距的列,否则我会将填充设置应用于容器div本身,而不是单个列:
例如,

<div class="container px-0 px-lg-3">

相关问题