Skip to content

Commit 9b3d07b

Browse files
committed
styles: Use range context queries to eliminate *_max variables.
On a high-DPI display or with a non-default zoom level, the browser viewport may have a width strictly between md_max = 767px and md_min = 768px. Use only the *_min bounds for consistency. This requires queries with strict inequalities to express upper bounds (width < md_min). Fortunately, that functionality is provided by range context queries. Unfortunately, those are not supported in all browsers. Fortunately, we can compile them away using postcss-media-minmax. Unfortunately, postcss-media-minmax currently subtracts 1px for strict inequalities anyway to work around a Safari rounding bug. Fortunately, 0.02px should be sufficient for that, so I submitted a PR: postcss/postcss-media-minmax#28 Signed-off-by: Anders Kaseorg <[email protected]>
1 parent be22233 commit 9b3d07b

28 files changed

+120
-123
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"postcss-calc": "^8.0.0",
5353
"postcss-extend-rule": "^3.0.0",
5454
"postcss-loader": "^4.0.2",
55+
"postcss-media-minmax": "https://github.com/andersk/postcss-media-minmax.git#01239f17f4a9872ace1dd133cee526a7de4ac9f5",
5556
"postcss-nested": "^5.0.0",
5657
"postcss-simple-vars": "^6.0.0",
5758
"regenerator-runtime": "^0.13.3",

postcss.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module.exports = {
1111
variables: media_breakpoints,
1212
},
1313
"postcss-calc": {},
14+
"postcss-media-minmax": {},
1415
autoprefixer: {},
1516
},
1617
};

static/js/css_variables.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,5 @@ module.exports = {
2222
ml_min: ml + "px",
2323
mm_min: mm + "px",
2424
ms_min: ms + "px",
25-
26-
xs_max: xs - 1 + "px",
27-
sm_max: sm - 1 + "px",
28-
md_max: md - 1 + "px",
29-
lg_max: lg - 1 + "px",
30-
xl_max: xl - 1 + "px",
31-
ml_max: ml - 1 + "px",
32-
mm_max: mm - 1 + "px",
33-
ms_max: ms - 1 + "px",
3425
},
3526
};

static/js/message_viewport.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ exports.is_narrow = function () {
307307
// This basically returns true when we hide the right sidebar for
308308
// the left_side_userlist skinny mode. It would be nice to have a less brittle
309309
// test for this.
310-
return window.innerWidth <= media_breakpoints.xl_max;
310+
return window.innerWidth < media_breakpoints.xl_min;
311311
};
312312

313313
exports.system_initiated_animate_scroll = function (scroll_amount) {

static/styles/alerts.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ $alert-error-red: hsl(0, 80%, 40%);
240240
}
241241

242242
/* @media queries */
243-
@media (max-width: $lg_max) {
243+
@media (width < $lg_min) {
244244
.alert-box {
245245
width: 80%;
246246
left: 10%;

static/styles/app_components.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@
268268
.stream_sorter_toggle {
269269
margin-left: auto;
270270

271-
@media (max-width: $lg_max) {
271+
@media (width < $lg_min) {
272272
margin-left: unset;
273273
}
274274
}
@@ -390,7 +390,7 @@
390390
}
391391
}
392392

393-
@media (max-width: $md_max) {
393+
@media (width < $md_min) {
394394
/* Override Bootstrap's responsive grid to display input at full width */
395395
.input-append .stream-list-filter {
396396
/* Input width = 100% - 10px margin x2 - 6px padding x2 - 1px border x2. */

static/styles/compose.css

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
line-height: 1em;
1717
}
1818

19-
@media (min-width: $sm_min) {
19+
@media (width >= $sm_min) {
2020
display: none;
2121
}
2222
}
@@ -33,7 +33,7 @@
3333
display: none;
3434
}
3535

36-
@media (max-width: $sm_max) {
36+
@media (width < $sm_min) {
3737
.compose_stream_button,
3838
.compose_private_button {
3939
display: none;
@@ -497,20 +497,20 @@ a#undo_markdown_preview {
497497
}
498498

499499
/* This max-width must be synced with message_viewport.is_narrow */
500-
@media (max-width: $xl_max) {
500+
@media (width < $xl_min) {
501501
.compose-content {
502502
margin-right: 7px;
503503
}
504504
}
505505

506-
@media (max-width: $md_max) {
506+
@media (width < $md_min) {
507507
.compose-content {
508508
margin-right: 7px;
509509
margin-left: 7px;
510510
}
511511
}
512512

513-
@media (max-width: $mm_max) {
513+
@media (width < $mm_min) {
514514
#stream_message_recipient_topic.recipient_box {
515515
width: calc(100% - 175px);
516516
min-width: 95px;

static/styles/drafts.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
display: flex;
1212
flex-direction: column;
1313

14-
@media (max-width: $md_max) {
14+
@media (width < $md_min) {
1515
height: 95%;
1616
max-width: none;
1717
width: 90%;
@@ -111,7 +111,7 @@
111111
right: -80px;
112112
font-size: 0.9em;
113113

114-
@media (max-width: $sm_max) {
114+
@media (width < $sm_min) {
115115
right: 0;
116116
}
117117

static/styles/informational_overlays.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@
122122
margin-bottom: 10px !important;
123123
}
124124

125-
@media only screen and (max-width: $md_max) {
125+
@media only screen and (width < $md_min) {
126126
.informational-overlays {
127127
.overlay-content {
128128
width: calc(100% - 20px);

static/styles/lightbox.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@
253253
}
254254
}
255255

256-
@media only screen and (min-width: $ms_min) and (max-width: $md_max) {
256+
@media only screen and ($ms_min <= width < $md_min) {
257257
#lightbox_overlay {
258258
.image-actions {
259259
float: left;

0 commit comments

Comments
 (0)