-
-
Notifications
You must be signed in to change notification settings - Fork 79.2k
create responsive containers #25631
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
create responsive containers #25631
Conversation
provide more flexibility and allow the user to determine when containers switch from fluid to fixed width.
|
It might be easier to comprehend if you can see the (desired) compiled code, so here is the CSS: .container,
.container-fluid,
.container-sm,
.container-md,
.container-lg,
.container-xl {
width: 100%;
padding-right: ($grid-gutter-width / 2);
padding-left: ($grid-gutter-width / 2);
margin-right: auto;
margin-left: auto;
}
@media (min-width: 576px) {
.container,
.container-sm {
max-width: 540px;
}
}
@media (min-width: 768px) {
.container,
.container-sm,
.container-md {
max-width: 720px;
}
}
@media (min-width: 992px) {
.container,
.container-sm,
.container-md,
.container-lg {
max-width: 960px;
}
}
@media (min-width: 1200px) {
.container,
.container-sm,
.container-md,
.container-lg,
.container-xl {
max-width: 1140px;
}
} |
|
ping @chasepalmer |
|
Hi @browner12 Thanks a lot for your contribution, the idea is clear and intresting, and I see how this can be useful. I got your branch and test it out and it works as it should. I don't know if the naming I'll be up to @mdo to decide on this one 😄 |
|
This is something I always meant to look into myself since I needed it for a project, but worked around it locally and forgot about it :) I'd like to see this merged too, so 👍 from me. |
|
Why not use the same approach here as is already being done with rows/columns: .container,
.container-fluid {
width: 100%;
padding-right: ($grid-gutter-width / 2);
padding-left: ($grid-gutter-width / 2);
margin-right: auto;
margin-left: auto;
}
@media (min-width: 576px) {
.container,
.container-sm {
max-width: 540px;
}
.container-sm-fluid {
width: 100%;
padding-right: ($grid-gutter-width / 2);
padding-left: ($grid-gutter-width / 2);
margin-right: auto;
margin-left: auto;
}
}
@media (min-width: 768px) {
.container,
.container-sm,
.container-md {
max-width: 720px;
}
.container-sm-fluid,
.container-md-fluid {
width: 100%;
padding-right: ($grid-gutter-width / 2);
padding-left: ($grid-gutter-width / 2);
margin-right: auto;
margin-left: auto;
}
}
@media (min-width: 992px) {
.container,
.container-sm,
.container-md,
.container-lg {
max-width: 960px;
}
.container-sm-fluid,
.container-md-fluid,
.container-lg-fluid {
width: 100%;
padding-right: ($grid-gutter-width / 2);
padding-left: ($grid-gutter-width / 2);
margin-right: auto;
margin-left: auto;
}
}
@media (min-width: 1200px) {
.container,
.container-sm,
.container-md,
.container-lg,
.container-xl {
max-width: 1140px;
}
.container-sm-fluid,
.container-md-fluid,
.container-lg-fluid,
.container-xl-fluid {
width: 100%;
padding-right: ($grid-gutter-width / 2);
padding-left: ($grid-gutter-width / 2);
margin-right: auto;
margin-left: auto;
}
}This will allow you to (if I did it right here) compose multiple like:
or
or
|
|
If we can give the user this full control for whether their breakpoint is fluid or fixed, I'm all for that. Even though I feel like switching from a fixed container on a smallish device to a fluid container on a largish device will be a very uncommon use case. My one concern with your code is we will need to reset the For example: <div class="container-fluid container-sm container-md-fluid"></div>The relevant media queries would be: @media (min-width: 576px) {
.container,
.container-sm {
max-width: 540px;
}
.container-sm-fluid {
width: 100%;
padding-right: ($grid-gutter-width / 2);
padding-left: ($grid-gutter-width / 2);
margin-right: auto;
margin-left: auto;
}
}
@media (min-width: 768px) {
.container,
.container-sm,
.container-md {
max-width: 720px;
}
.container-sm-fluid,
.container-md-fluid {
width: 100%;
padding-right: ($grid-gutter-width / 2);
padding-left: ($grid-gutter-width / 2);
margin-right: auto;
margin-left: auto;
}
}This would mean on a device >768px even though it has a |
|
any movement on this? I'm not sure what the turnaround time is like on new features in this repo. |
|
sorry @patrickhlauke, the way you read it is not at all the way I meant it. just legitimately curious if we like to take the new features a little slower to flesh them out more. For the projects I contribute to, I have a better understanding of the pacing of things, and was just trying to get a feel for BS. I absolutely share your sentiment on people feeling entitled to OSS, and thanks for all you do in this project. |
|
yeah sorry, flew off the handle there...hence deleted the comment. missed the context that this was a PR as well. |
|
@browner12 Sorry for the delay! I'm going to pull this down and write some docs for it. |
|
Checking it out locally, the code doesn't generate what you've put into your desired output comment. |
|
yah, i think i need some help with the Sass. i'll give it a shot this week |
|
Yeah, I'll see about trying to take another look, too :). These layers of loops, maps, and what not always trip me up. |
this commit fixes the non-media portion of the generated CSS. I learned about the `@extends` directive and was able to put it to good use. I create a new temporary map that contains all the main `$container-max-widths` and join it to our 2 special cases of 'xs' and 'fluid'. Then we loop through that and, with the appropriate infixes, extend our placeholder
forgot to run my tests before the last push, i think these are better.
|
@mdo I was able to clean up the top part with an I'm running into an issue in the media queries where
which I feel shouldn't apply because I'm trying to extend a selector from within the media query. Any thoughts on that part? |
using the `@extend` directive I was able to clean up this code
|
alright @mdo the new commits are now generating the desired code so this should be ready for review. |
|
bump |
|
could we put this on either the 4.2 or 4.3 project board? |
|
What is the purpose of this PR? |
|
the first comment is a pretty elaborate explanation of what it does and why it's needed. if there's a specific part you're confused about, I'd be happy to answer. |
|
@browner12 Haven't forgotten about this. v4.2 is up after v4.1.2, so stay tuned! |
|
thanks @mdo ! 4.1 and 4.2 are looking great! |
I usually find myself on the same boat and my solution matches the one from @mdo. In my experience, when you build a mobile-first responsive website, you want your layout to take the full width of the device screen, usually up to an hd screen desktop. With @mdo approach, you would set the |
We avoid using `@extend` whenever possible, and this is more readable
|
@Tylerian so if I'm understanding you correctly, you would want IMO, this looks silly, and is not a common use case. As I stated before, this takes away the responsiveness of the container, and people should write their own code for this. Do you have a live example where you've used it this way? It might be helpful for me to see. |
|
If you liked the original functionality of this PR, please voice your concern on the new one. It has been merged, and completely changes how this feature will work. |
This PR fixes the responsive containers that were added in #29095, originally stubbed out in #25631. Apologies to @browner12 for getting that wrong. Fixes #25631.
This PR fixes the responsive containers that were added in #29095, originally stubbed out in #25631. Apologies to @browner12 for getting that wrong. Fixes #25631.
This PR fixes the responsive containers that were added in #29095, originally stubbed out in #25631. Apologies to @browner12 for getting that wrong. Fixes #25631.
* Follow-up to #29095 This PR fixes the responsive containers that were added in #29095, originally stubbed out in #25631. Apologies to @browner12 for getting that wrong. Fixes #25631. * update navbar as well because we cannot reset all containers uniformly * Update navbars example to include container-xl example to ensure containers match * rewrite responsive containers docs, add table of max-widths * Update container docs - Move table up to the intro - Remove the container example because it's actually hella confusing - Update and link to grid example as a demo instead
|
hallelujah, thanks guys! |
* Follow-up to #29095 This PR fixes the responsive containers that were added in #29095, originally stubbed out in #25631. Apologies to @browner12 for getting that wrong. Fixes #25631. * update navbar as well because we cannot reset all containers uniformly * Update navbars example to include container-xl example to ensure containers match * rewrite responsive containers docs, add table of max-widths * Update container docs - Move table up to the intro - Remove the container example because it's actually hella confusing - Update and link to grid example as a demo instead
* Follow-up to #29095 This PR fixes the responsive containers that were added in #29095, originally stubbed out in #25631. Apologies to @browner12 for getting that wrong. Fixes #25631. * update navbar as well because we cannot reset all containers uniformly * Update navbars example to include container-xl example to ensure containers match * rewrite responsive containers docs, add table of max-widths * Update container docs - Move table up to the intro - Remove the container example because it's actually hella confusing - Update and link to grid example as a demo instead
* Follow-up to #29095 This PR fixes the responsive containers that were added in #29095, originally stubbed out in #25631. Apologies to @browner12 for getting that wrong. Fixes #25631. * update navbar as well because we cannot reset all containers uniformly * Update navbars example to include container-xl example to ensure containers match * rewrite responsive containers docs, add table of max-widths * Update container docs - Move table up to the intro - Remove the container example because it's actually hella confusing - Update and link to grid example as a demo instead
|
Just for clarification. This will go into 4.4 as described by @browner12 in the initial post? |
|
@jandante: Yes, you can view the ship list here: #29096 The |
* Follow-up to twbs#29095 This PR fixes the responsive containers that were added in twbs#29095, originally stubbed out in twbs#25631. Apologies to @browner12 for getting that wrong. Fixes twbs#25631. * update navbar as well because we cannot reset all containers uniformly * Update navbars example to include container-xl example to ensure containers match * rewrite responsive containers docs, add table of max-widths * Update container docs - Move table up to the intro - Remove the container example because it's actually hella confusing - Update and link to grid example as a demo instead
| // few properties so that content nested within behave properly. | ||
| > .container, | ||
| > .container-fluid { | ||
| > [class^="container"] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That selector selects only items where class attribute starts with container word, this is more "secure" selector:
> [class^="container"],
> [class*=" container"] {| @include media-breakpoint-down($breakpoint) { | ||
| > .container, | ||
| > .container-fluid { | ||
| > [class^=".container"] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above but the dot has to be removed:
> [class^="container"],
> [class*=" container"] {| // For nesting containers, have to redeclare for alignment purposes | ||
| > .container, | ||
| > .container-fluid { | ||
| > [class^=".container"] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👆👆👆 same...
Motivation
Currently with
.containerand.container-fluidwe have an all or nothing approach to either a full width or fixed width layout. I would like to make these containers responsive to give the end user full control over when the switch to a fixed width layout occurs.It was brought up in PR #24903 , and discussed on the Slack channel. The use case I am addressing in this PR is actually the opposite of what's being asked in the other one, because I see this as the more 99% use case.
Example
The most common use case I see is the user who wants their extra small and small devices to maintain a fluid layout since real estate is at a premium, and only switch to a fixed layout on medium devices and larger where you have much more width.
Approach
If you dig into the source on containers you realize that on extra small devices,
.containerand.container-fluidare the same. It's not until you hit the larger sizes thatmax-widths start getting applied. The approach I use is similar to all the other responsive classes where styling is applied to the breakpoint and up. This PR introduces 4 new classes which can be used in place of existing container classes..container-sm.container-md.container-lg.container-xlAs an example,
would mean the container stays fluid until you hit the medium breakpoint, and from there on up it would be fixed width. This table gives you a full breakdown.
.container.container-sm.container-md.container-lg.container-xl.container-fluidAs you can see, the
.containerand.container-fluidmaintain the same functionality so backwards compatibility is maintained.Next Steps
I imagine this PR will require a decent amount of discussion. One point to address is if it is worth it to be able to go the other direction as well, and switch from a fixed layout to a fluid layout after a certain breakpoint.
Also, I'm sure I could also use some help on optimizing the SCSS.