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

Media query mixins #13014

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/css/bootstrap.css.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/assets/js/customize.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/assets/js/raw-files.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/dist/css/bootstrap.css.map

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions less/forms.less
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ input[type="checkbox"],
.form-inline {

// Kick in the inline
@media (min-width: @screen-sm-min) {
.screen-sm({
// Inline-block all the things for "inline"
.form-group {
display: inline-block;
Expand Down Expand Up @@ -410,12 +410,12 @@ input[type="checkbox"],

// Validation states
//
// Reposition the icon because it's now within a grid column and columns have
// Reposition the icon because it is now within a grid column and columns have
// `position: relative;` on them. Also accounts for the grid gutter padding.
.has-feedback .form-control-feedback {
top: 0;
}
}
});
}


Expand Down Expand Up @@ -456,13 +456,13 @@ 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.
@media (min-width: @screen-sm-min) {
.screen-sm({
.control-label {
text-align: right;
margin-bottom: 0;
padding-top: (@padding-base-vertical + 1); // Default padding plus a border
}
}
});

// Validation states
//
Expand Down
24 changes: 12 additions & 12 deletions less/grid.less
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
.container {
.container-fixed();

@media (min-width: @screen-sm-min) {
.screen-sm({
width: @container-sm;
}
@media (min-width: @screen-md-min) {
});
.screen-md({
width: @container-md;
}
@media (min-width: @screen-lg-min) {
});
.screen-lg({
width: @container-lg;
}
});
}


Expand Down Expand Up @@ -61,24 +61,24 @@
// Columns, offsets, pushes, and pulls for the small device range, from phones
// to tablets.

@media (min-width: @screen-sm-min) {
.screen-sm({
.make-grid(sm);
}
});


// Medium grid
//
// Columns, offsets, pushes, and pulls for the desktop device range.

@media (min-width: @screen-md-min) {
.screen-md({
.make-grid(md);
}
});


// Large grid
//
// Columns, offsets, pushes, and pulls for the large desktop device range.

@media (min-width: @screen-lg-min) {
.screen-lg({
.make-grid(lg);
}
});
4 changes: 4 additions & 0 deletions less/mixins.less
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Mixins
// --------------------------------------------------


// Utilities
@import "mixins/media-queries.less";
@import "mixins/hide-text.less";
@import "mixins/opacity.less";
@import "mixins/image.less";
Expand Down Expand Up @@ -37,3 +39,5 @@
@import "mixins/nav-vertical-align.less";
@import "mixins/grid-framework.less";
@import "mixins/grid.less";


48 changes: 24 additions & 24 deletions less/mixins/grid.less
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,25 @@
padding-left: (@gutter / 2);
padding-right: (@gutter / 2);

@media (min-width: @screen-sm-min) {
.screen-sm({
float: left;
width: percentage((@columns / @grid-columns));
}
});
}
.make-sm-column-offset(@columns) {
@media (min-width: @screen-sm-min) {
.screen-sm({
margin-left: percentage((@columns / @grid-columns));
}
});
}
.make-sm-column-push(@columns) {
@media (min-width: @screen-sm-min) {
.screen-sm({
left: percentage((@columns / @grid-columns));
}
});
}
.make-sm-column-pull(@columns) {
@media (min-width: @screen-sm-min) {
.screen-sm({
right: percentage((@columns / @grid-columns));
}
});
}

// Generate the medium columns
Expand All @@ -72,25 +72,25 @@
padding-left: (@gutter / 2);
padding-right: (@gutter / 2);

@media (min-width: @screen-md-min) {
.screen-sm({
float: left;
width: percentage((@columns / @grid-columns));
}
});
}
.make-md-column-offset(@columns) {
@media (min-width: @screen-md-min) {
.screen-sm({
margin-left: percentage((@columns / @grid-columns));
}
});
}
.make-md-column-push(@columns) {
@media (min-width: @screen-md-min) {
.screen-sm({
left: percentage((@columns / @grid-columns));
}
});
}
.make-md-column-pull(@columns) {
@media (min-width: @screen-md-min) {
.screen-sm({
right: percentage((@columns / @grid-columns));
}
});
}

// Generate the large columns
Expand All @@ -100,23 +100,23 @@
padding-left: (@gutter / 2);
padding-right: (@gutter / 2);

@media (min-width: @screen-lg-min) {
.screen-lg({
float: left;
width: percentage((@columns / @grid-columns));
}
});
}
.make-lg-column-offset(@columns) {
@media (min-width: @screen-lg-min) {
.screen-lg({
margin-left: percentage((@columns / @grid-columns));
}
});
}
.make-lg-column-push(@columns) {
@media (min-width: @screen-lg-min) {
.screen-lg({
left: percentage((@columns / @grid-columns));
}
});
}
.make-lg-column-pull(@columns) {
@media (min-width: @screen-lg-min) {
.screen-lg({
right: percentage((@columns / @grid-columns));
}
});
}
26 changes: 26 additions & 0 deletions less/mixins/media-queries.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Media query mixins

.screen-xs(@rules) {
@media (max-width: @screen-xs-max) { @rules(); }
}

.screen-sm(@rules) {
@media (min-width: @screen-sm-min) { @rules(); }
}

.screen-sm-max(@rules) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-max doesn't seem too clear, IMHO. Maybe .screen-sm-only ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I don't think screen is that great either as it actually isn't representing a query that explicitly targets screen. I definitely think we should iron out the names before merging this. They could be better.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The query doesn't target 'screen' media but it uses the @screen-* variables as reference.

I also think, that the naming is misleading. .screen-sm() should cover only small screens while .screen-sm-max() should cover small screens and below. There should also be a third mixin .screen-sm-min() which covers small screens an above. Same for medium screen queries...

I made a revision of my previous gist to clarify what i mean. I think you just adopted the names from the first dirty version. This revision also contains some .screen() mixins to quickly assign rules to multiple media queries.

@media (min-width: @screen-sm-min) and (max-width: @screen-sm-max) { @rules(); }
}

.screen-md(@rules) {
@media (min-width: @screen-md-min) { @rules(); }
}

.screen-md-max(@rules) {
@media (min-width: @screen-md-min) and (max-width: @screen-md-max) { @rules(); }
}

.screen-lg(@rules) {
@media (min-width: @screen-lg-min) { @rules(); }
}

10 changes: 5 additions & 5 deletions less/modals.less
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@
}

// Scale up the modal
@media (min-width: @screen-sm-min) {
// Automatically set modal's width for larger viewports
.screen-sm({
// Automatically set modal\'s width for larger viewports
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary backslash?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cvrebert I made a comment about that in the commit - but maybe it's worth adding a comment in the file itself. That is needed to escape the ' which for some reason causes a parsing error in that comment once you use a mixin with a ruleset. Other option would be to have bad punctuation and just drop the ' altogether.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's report that upstream to the Less folks—we make extensive use of apostrophes 😁.

.modal-dialog {
width: @modal-md;
margin: 30px auto;
Expand All @@ -131,8 +131,8 @@

// Modal sizes
.modal-sm { width: @modal-sm; }
}
});

@media (min-width: @screen-md-min) {
.screen-md({
.modal-lg { width: @modal-lg; }
}
});
8 changes: 4 additions & 4 deletions less/navs.less
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,15 @@
left: auto;
}

@media (min-width: @screen-sm-min) {
.screen-sm({
> li {
display: table-cell;
width: 1%;
> a {
margin-bottom: 0;
}
}
}
});
}

// Move borders to anchors instead of bottom of list
Expand All @@ -202,7 +202,7 @@
border: 1px solid @nav-tabs-justified-link-border-color;
}

@media (min-width: @screen-sm-min) {
.screen-sm({
> li > a {
border-bottom: 1px solid @nav-tabs-justified-link-border-color;
border-radius: @border-radius-base @border-radius-base 0 0;
Expand All @@ -212,7 +212,7 @@
> .active > a:focus {
border-bottom-color: @nav-tabs-justified-active-link-border-color;
}
}
});
}


Expand Down
Loading