Commit c8bfa7d3 authored by Chris Rebert's avatar Chris Rebert

Merge pull request #54 from twbs/overhaul-responsive-visibility

Overhaul of responsive visibility classes
parents ff9c07f4 e651b48e
......@@ -1244,10 +1244,7 @@ body {
.visible-on,
.hidden-on {
.col-xs-6 {
.hidden-xs,
.hidden-sm,
.hidden-md,
.hidden-lg {
> .not-visible {
color: #999;
border: 1px solid #ddd;
}
......@@ -1256,10 +1253,7 @@ body {
.visible-on,
.hidden-on {
.col-xs-6 {
.visible-xs-block,
.visible-sm-block,
.visible-md-block,
.visible-lg-block {
.visible {
color: #468847;
background-color: #dff0d8;
border: 1px solid #d6e9c6;
......@@ -1267,6 +1261,32 @@ body {
}
}
@include media-breakpoint-only(xs) {
.hidden-xs-only {
display: none !important;
}
}
@include media-breakpoint-only(sm) {
.hidden-sm-only {
display: none !important;
}
}
@include media-breakpoint-only(md) {
.hidden-md-only {
display: none !important;
}
}
@include media-breakpoint-only(lg) {
.hidden-lg-only {
display: none !important;
}
}
@include media-breakpoint-only(xl) {
.hidden-xl-only {
display: none !important;
}
}
//
// Brand guidelines
//
......
......@@ -7,48 +7,64 @@ Since Bootstrap is designed to be mobile-first, we employ media queries in our C
### Common queries
Bootstrap uses the following media query ranges in our source Sass files for key breakpoints in our layout, grid system, and components.
Bootstrap mainly uses the following media query ranges in our source Sass files for key breakpoints in our layout, grid system, and components.
{% highlight scss %}
/* Extra small devices (phones, less than 768px) */
/* Extra small devices (portrait phones, less than ???px) */
/* No media query since this is the default in Bootstrap */
/* Small devices (tablets, 768px and up) */
@media (min-width: @screen-sm-min) { ... }
/* Small devices (landscape phones, 34em and up) */
@media (min-width: 34em) { ... }
/* Medium devices (desktops, 992px and up) */
@media (min-width: @screen-md-min) { ... }
/* Medium devices (tablets, 48em and up) */
@media (min-width: 48em) { ... }
/* Large devices (large desktops, 1200px and up) */
@media (min-width: @screen-lg-min) { ... }
{% endhighlight %}
/* Large devices (desktops, 62em and up) */
@media (min-width: 62em) { ... }
We occasionally expand on these media queries to include a <code>max-width</code> to limit CSS to a narrower set of devices.
/* Extra large devices (large desktops, 75em and up) */
@media (min-width: 75em) { ... }
{% endhighlight %}
These media queries are available via Sass mixins:
{% highlight scss %}
@media (max-width: @screen-xs-max) { ... }
@media (min-width: @screen-sm-min) and (max-width: @screen-sm-max) { ... }
@media (min-width: @screen-md-min) and (max-width: @screen-md-max) { ... }
@media (min-width: @screen-lg-min) { ... }
@include media-breakpoint-up(xs) { ... }
@include media-breakpoint-up(sm) { ... }
@include media-breakpoint-up(md) { ... }
@include media-breakpoint-up(lg) { ... }
@include media-breakpoint-up(lxl) { ... }
// Example usage:
@include media-breakpoint-up(sm) {
.some-class {
display: block;
}
}
{% endhighlight %}
### Sass mixins
We occasionally use media queries that go in the other direction (the given screen size *or smaller*):
{% highlight scss %}
/* Extra small devices (portrait phones, less than 34em) */
@media (max-width: 33.9em) { ... }
/* Small devices (landscape phones, less than 48em) */
@media (max-width: 47.9em) { ... }
/* Medium devices (tablets, less than 62em) */
@media (max-width: 61.9em) { ... }
The above media queries are also available via Sass mixins:
/* Large devices (desktops, less than 75em) */
@media (max-width: 74.9em) { ... }
/* Extra large devices (large desktops) */
/* No media query since the extra-large breakpoint has no upper bound on its width */
{% endhighlight %}
These media queries are available via Sass mixins:
{% highlight scss %}
// List of mixins
@include media-xs { ... }
@include media-sm { ... }
@include media-sm-max { ... }
@include media-md { ... }
@include media-md-max { ... }
@include media-lg { ... }
// Usage
@include media-xs {
.element {
display: block;
}
}
@include media-breakpoint-down(xs) { ... }
@include media-breakpoint-down(sm) { ... }
@include media-breakpoint-down(md) { ... }
@include media-breakpoint-down(lg) { ... }
@include media-breakpoint-down(lxl) { ... }
{% endhighlight %}
This diff is collapsed.
......@@ -67,6 +67,8 @@ The following deprecated Less/SCSS variables have been removed in v4.0.0:
* `@screen-xs`, `@screen-xs-min`. The extra small breakpoint has no lower bound, so these variables were logically absurd. Reformulate your expression in terms of `$screen-xs-max` instead.
* `@grid-float-breakpoint`
The responsive utility classes have been overhauled. The old classes (`.hidden-xs` `.hidden-sm` `.hidden-md` `.hidden-lg` `.visible-xs-block` `.visible-xs-inline` `.visible-xs-inline-block` `.visible-sm-block` `.visible-sm-inline` `.visible-sm-inline-block` `.visible-md-block` `.visible-md-inline` `.visible-md-inline-block` `.visible-lg-block` `.visible-lg-inline` `.visible-lg-inline-block`) are gone. They have been replaced by `.hidden-xs-up` `.hidden-xs-down` `.hidden-sm-up` `.hidden-sm-down` `.hidden-md-up` `.hidden-md-down` `.hidden-lg-up` `.hidden-lg-down`. The `.hidden-*-up` classes hide the element when the viewport is at the given breakpoint or wider (e.g. `.hidden-md-up` hides an element on medium, large, and extra-large devices). The `.hidden-*-down` classes hide the element when the viewport is at the given breakpoint or smaller (e.g. `.hidden-md-down` hides an element on extra-small, small, and medium devices). Rather than using explicit `.visible-*` classes, you make an element visible by simply not hiding it at that screen size. You can combine one `.hidden-*-up` class with one `.hidden-*-down` class to show an element only on a given interval of screen sizes (e.g. `.hidden-sm-down.hidden-xl-up` shows the element only on medium and large devices). Note that the changes to the grid breakpoints in v4 means that you'll need to go one breakpoint larger to achieve the same results (e.g. `.hidden-md` is more similar to `.hidden-lg-down` than to `.hidden-md-down`). .The new responsive utility classes don't attempt to accommodate less common cases where an element's visibility can't be expressed as a single contiguous range of viewport sizes; you will instead need to use custom CSS in such cases.
## Misc notes to prioritize
- Removed the `min--moz-device-pixel-ratio` typo hack for retina media queries
......
......@@ -218,7 +218,7 @@
// Scale up controls for tablets and up
@include media-sm {
@include media-breakpoint-up(sm) {
// Scale up the controls a smidge
.carousel-control {
.icon-prev,
......
......@@ -195,7 +195,7 @@
//
// TODO: remove?
// @include media-sm {
// @include media-breakpoint-up(sm) {
// .navbar-right {
// .dropdown-menu {
// .dropdown-menu-right();
......
......@@ -416,7 +416,7 @@ input[type="checkbox"] {
.form-inline {
// Kick in the inline
@include media-sm {
@include media-breakpoint-up(sm) {
// Inline-block all the things for "inline"
.form-group {
display: inline-block;
......@@ -516,7 +516,7 @@ input[type="checkbox"] {
// Reset spacing and right align labels, but scope to media queries so that
// labels on narrow viewports stack the same as a default form example.
@include media-sm {
@include media-breakpoint-up(sm) {
.control-label {
padding-top: ($padding-base-vertical + .1); // Default padding plus a border
margin-bottom: 0;
......@@ -537,14 +537,14 @@ input[type="checkbox"] {
// Quick utility class for applying `.input-lg` and `.input-sm` styles to the
// inputs and labels within a `.form-group`.
.form-group-lg {
@include media-sm {
@include media-breakpoint-up(sm) {
.control-label {
padding-top: $padding-lg-vertical;
}
}
}
.form-group-sm {
@include media-sm {
@include media-breakpoint-up(sm) {
.control-label {
padding-top: ($padding-sm-vertical + .1);
}
......
......@@ -12,7 +12,7 @@
// For each breakpoint, define the maximum width of the container in a media query
@each $breakpoint, $container-max-width in $container-max-widths {
@include media-breakpoint-min($breakpoint) {
@include media-breakpoint-up($breakpoint) {
max-width: $container-max-width;
}
}
......
......@@ -19,7 +19,7 @@
border-top-color: darken($jumbotron-bg, 10%);
}
@include media-sm {
@include media-breakpoint-up(sm) {
.jumbotron {
padding: ($jumbotron-padding * 2) $jumbotron-padding;
}
......
......@@ -25,7 +25,6 @@
// Utilities
@import "mixins/breakpoints";
@import "mixins/media-queries";
@import "mixins/hide-text";
@import "mixins/image";
@import "mixins/label";
......
......@@ -126,7 +126,7 @@
}
// Scale up the modal
@include media-sm {
@include media-breakpoint-up(sm) {
// Automatically set modal's width for larger viewports
.modal-dialog {
width: $modal-md;
......@@ -140,6 +140,6 @@
.modal-sm { width: $modal-sm; }
}
@include media-md {
@include media-breakpoint-up(md) {
.modal-lg { width: $modal-lg; }
}
......@@ -14,7 +14,7 @@
margin-bottom: $navbar-margin-bottom;
@include clearfix;
@include media-sm {
@include media-breakpoint-up(sm) {
@include border-radius($navbar-border-radius);
}
}
......@@ -30,7 +30,7 @@
.navbar-static-top {
z-index: $zindex-navbar;
@include media-sm {
@include media-breakpoint-up(sm) {
@include border-radius(0);
}
}
......@@ -45,7 +45,7 @@
margin-bottom: 0; // override .navbar defaults
// Undo the rounded corners
@include media-sm {
@include media-breakpoint-up(sm) {
@include border-radius(0);
}
}
......@@ -119,7 +119,7 @@
@extend .form-inline;
.form-group {
@include media-sm {
@include media-breakpoint-up(sm) {
margin-bottom: 5px;
&:last-child {
......@@ -132,7 +132,7 @@
// @include navbar-vertical-align($input-height-base);
// Undo 100% width for pull classes
@include media-sm {
@include media-breakpoint-up(sm) {
width: auto;
padding-top: 0;
padding-bottom: 0;
......@@ -181,7 +181,7 @@
.navbar-text {
// @include navbar-vertical-align($line-height-computed);
@include media-sm {
@include media-breakpoint-up(sm) {
float: left;
margin-right: $navbar-padding-horizontal;
margin-left: $navbar-padding-horizontal;
......@@ -197,7 +197,7 @@
//
// Declared after the navbar components to ensure more specificity on the margins.
@include media-sm {
@include media-breakpoint-up(sm) {
.navbar-left {
@include pull-left();
}
......
......@@ -2,6 +2,19 @@
// Responsive: Utility classes
// --------------------------------------------------
@each $bp in map-keys($grid-breakpoints) {
.hidden-#{$bp}-up {
@include media-breakpoint-up($bp) {
display: none !important;
}
}
.hidden-#{$bp}-down {
@include media-breakpoint-down($bp) {
display: none !important;
}
}
}
// IE10 in Windows (Phone) 8
//
......@@ -23,98 +36,6 @@
}
.visible-xs-block,
.visible-xs-inline,
.visible-xs-inline-block,
.visible-sm-block,
.visible-sm-inline,
.visible-sm-inline-block,
.visible-md-block,
.visible-md-inline,
.visible-md-inline-block,
.visible-lg-block,
.visible-lg-inline,
.visible-lg-inline-block {
display: none !important;
}
.visible-xs-block {
@include media-xs {
display: block !important;
}
}
.visible-xs-inline {
@include media-xs {
display: inline !important;
}
}
.visible-xs-inline-block {
@include media-xs {
display: inline-block !important;
}
}
.visible-sm-block {
@include media-sm-max {
display: block !important;
}
}
.visible-sm-inline {
@include media-sm-max {
display: inline !important;
}
}
.visible-sm-inline-block {
@include media-sm-max {
display: inline-block !important;
}
}
.visible-md-block {
@include media-md-max {
display: block !important;
}
}
.visible-md-inline {
@include media-md-max {
display: inline !important;
}
}
.visible-md-inline-block {
@include media-md-max {
display: inline-block !important;
}
}
.visible-lg-block {
@include media-lg {
display: block !important;
}
}
.visible-lg-inline {
@include media-lg {
display: inline !important;
}
}
.visible-lg-inline-block {
@include media-lg {
display: inline-block !important;
}
}
@include media-sm-max {
@include responsive-invisibility(".hidden-sm");
}
@include media-md-max {
@include responsive-invisibility(".hidden-md");
}
@include media-lg {
@include responsive-invisibility(".hidden-lg");
}
// Print utilities
//
// Media queries are placed on the inside to be mixin-friendly.
......
......@@ -39,7 +39,8 @@
}
// Media of at least the minimum breakpoint width. No query for the smallest breakpoint.
@mixin media-breakpoint-min($name, $breakpoints: $grid-breakpoints) {
// Makes the @content apply to the given breakpoint and wider.
@mixin media-breakpoint-up($name, $breakpoints: $grid-breakpoints) {
$min: breakpoint-min($name, $breakpoints);
@if $min {
@media (min-width: $min) {
......@@ -51,7 +52,8 @@
}
// Media of at most the maximum breakpoint width. No query for the largest breakpoint.
@mixin media-breakpoint-max($name, $breakpoints: $grid-breakpoints) {
// Makes the @content apply to the given breakpoint and narrower.
@mixin media-breakpoint-down($name, $breakpoints: $grid-breakpoints) {
$max: breakpoint-max($name, $breakpoints);
@if $max {
@media (max-width: $max) {
......@@ -64,6 +66,7 @@
// Media between the breakpoint's minimum and maximum widths.
// No minimum for the smallest breakpoint, and no maximum for the largest one.
// Makes the @content apply only to the given breakpoint, not viewports any wider or narrower.
@mixin media-breakpoint-only($name, $breakpoints: $grid-breakpoints) {
// Nested media query combination does not work in libsass yet
// https://github.com/sass/libsass/issues/185
......@@ -76,8 +79,8 @@
}
} @else {
// One of min or max is a no-op, so this branch is not affected by libsass#185
@include media-breakpoint-min($name, $breakpoints) {
@include media-breakpoint-max($name, $breakpoints) {
@include media-breakpoint-up($name, $breakpoints) {
@include media-breakpoint-down($name, $breakpoints) {
@content;
}
}
......
......@@ -19,7 +19,7 @@
@extend %grid-column;
}
}
@include media-breakpoint-min($breakpoint) {
@include media-breakpoint-up($breakpoint) {
// Work around cross-media @extend (https://github.com/sass/sass/issues/1050)
%grid-column-float-#{$breakpoint} {
float: left;
......
// Media query mixins for default breakpoints
@mixin media-xs() {
@include media-breakpoint-max(xs) { @content }
}
@mixin media-sm() {
@include media-breakpoint-min(sm) { @content }
}
@mixin media-sm-max() {
@include media-breakpoint-only(sm) { @content }
}
@mixin media-md() {
@include media-breakpoint-min(md) { @content }
}
@mixin media-md-max() {
@include media-breakpoint-only(md) { @content }
}
@mixin media-lg() {
@include media-breakpoint-min(lg) { @content }
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment