-
-
Notifications
You must be signed in to change notification settings - Fork 79k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add responsive spacing utility classes #18490
Comments
The current v4 spacing utilities are very useful for laying out a page, but are ineffective in a responsive layout as they're a fixed size. For example, Introducing a breakpoint-and-up based system would make it consistent to the other utilities like text alignment and floats (eg That said, this feels akin to the responsive typography discussion (eg #17095); perhaps at least add documentation for the best practice for making spacing utilities responsive. |
Not going to happen. It'd multiply the number of classes we have for that stuff by five, one set for each tier. These are utilities, they're not meant to serve every use case. |
Understandable @mdo, what do you recommend as a replacement? |
May be? <div class="m-t-1 hidden-sm-up"></div> |
@mdo: A lot of people are asking for responsive spacing utility classes. Shouldn't it be considered to add these classes? IMO there are a lot of use-cases for it. If you worry about the file-size there could be a |
What @sergej2705 said. |
Pretty big oversight here. The padding/margin classes should adjust based on viewport width. |
@pi-mont There's no oversight, I said no to them. I'm still no to them until we at least get the rest of v4 in shipping order, too. |
I understand you said no, the oversight was in thinking that only one set of padding and margin classes would suit all viewports. |
This is one of the first search results for this feature, so I thought I'd share my solution here. My designer requested:
So I created my own classes based on what I found on @each $size, $lengths in $spacers {
$length-x: map-get($lengths, x);
$length-y: map-get($lengths, y);
@each $prop, $abbrev in (margin: m, padding: p) {
@each $breakpoint in map-keys($grid-breakpoints) {
.#{$abbrev}-#{$breakpoint}-x-#{$size} {
@include media-breakpoint-up($breakpoint) {
#{$prop}-right: $length-x !important;
#{$prop}-left: $length-x !important;
}
}
}
}
} As they say, the number of classes grows considerably, but it's fine for our project. |
This will be be revisited alongside #20934, which focuses on the |
#20934 was merged, yay! |
Was surprised to see this had been resolved in the latest alpha, |
It would be nice to have responsive spacing utility classes to manage gutters easily.
like
p-xs-a-2
wherexs
is breakpoint and2
is a kind of multiplation factor for$spacer
value.It would be also nice to keep abbreviations like
md, lg
for only breakpoints to reduce the confusion.And classes like
.m-xs-auto
,.m-xl-auto
would be great for responsively centering block elements.The text was updated successfully, but these errors were encountered: