Getbootstrap.com instructs, for putting CSS margin-bottom:4rem;
on, say, images
The classes are named using the format
{property}{sides}-{size}
forxs
and{property}{sides}-{breakpoint}-{size}
forsm
,md
,lg
, andxl
.
The problem is that using the xs format, {property}{sides}-{size}
, which would be mb-4
, will apply the same margin-bottom spacing to sm
, md
, lg
, and xl
as well.
Does anyone know a trick to apply the margin-bottom
spacing in Bootstrap to xs
and only xs
screens? What I am looking for is something like an "if statement" in Bootstrap.
The classes are named using the format {property}{sides}-{size} for xs and {property}{sides}-{breakpoint}-{size} for sm , md , lg , and xl . Where property is one of: m - for classes that set margin.
mb - for classes that set margin-bottom. ml - for classes that set margin-left. mr - for classes that set margin-right. mx - for classes that set both margin-left and margin-right.
Since the classes apply their styles in increasing screen size and CSS is cascading you can use the second class to override the first one. In your example that could be:
<div class="mb-4 mb-sm-0"></div>
which overrides the first class, when the second one activates.
.mb-4 { margin-bottom: 1.5rem !important; } @media (min-width: 576px) { .mb-sm-0 { margin-bottom: 0 !important; } }
<div class="mb-4 mb-sm-0"></div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With