Skip to content
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

Closed
maryleloisa opened this issue Dec 9, 2015 · 13 comments
Closed

Add responsive spacing utility classes #18490

maryleloisa opened this issue Dec 9, 2015 · 13 comments

Comments

@maryleloisa
Copy link

It would be nice to have responsive spacing utility classes to manage gutters easily.

like p-xs-a-2 where xs is breakpoint and 2 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.

@cvrebert cvrebert changed the title Add responsive spacing utility class Add responsive spacing utility classes Dec 9, 2015
@davidjb
Copy link
Contributor

davidjb commented Jan 14, 2016

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, .m-a-3 is useful at lg or xl breakpoints (where the margin is, by default, 48px (3*1rem)). However, on smaller viewports, especially xs, the margin now uses a fair proportion of the screen (eg 30% at 320px wide or ~18% at 543px).

Introducing a breakpoint-and-up based system would make it consistent to the other utilities like text alignment and floats (eg .text-md-center centres for md and up), but would add complexity.

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.

@mdo
Copy link
Member

mdo commented Jan 14, 2016

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.

@mdo mdo closed this as completed Jan 14, 2016
@guylepage3
Copy link

Understandable @mdo, what do you recommend as a replacement?

@woto
Copy link

woto commented Apr 9, 2016

May be?

<div class="m-t-1 hidden-sm-up"></div>

@sergej2705
Copy link
Contributor

@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 $enable-responsive-spacing-variable to switch it on if needed.

@leggomuhgreggo
Copy link

What @sergej2705 said.

@montoulieu
Copy link

Pretty big oversight here. The padding/margin classes should adjust based on viewport width.

@mdo
Copy link
Member

mdo commented Aug 22, 2016

@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.

@montoulieu
Copy link

I understand you said no, the oversight was in thinking that only one set of padding and margin classes would suit all viewports.

@colltoaction
Copy link

This is one of the first search results for this feature, so I thought I'd share my solution here.

My designer requested:

  • when on mobile, 1rem horizontal padding
  • tablet, 1.5rem
  • large screens, 3rem

So I created my own classes based on what I found on _spacing.scss:

@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.

@mdo
Copy link
Member

mdo commented Oct 26, 2016

This will be be revisited alongside #20934, which focuses on the display utilities.

@mdo mdo reopened this Oct 26, 2016
@mdo mdo added this to the v4.0.0-alpha.6 milestone Oct 26, 2016
@mdo
Copy link
Member

mdo commented Nov 1, 2016

#20934 was merged, yay!

@montoulieu
Copy link

Was surprised to see this had been resolved in the latest alpha,
Excellent work @tinchou!

@twbs twbs locked and limited conversation to collaborators Jun 15, 2017
@twbs twbs deleted a comment from dmanzer2 Jun 15, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

10 participants