question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Additional range selectors

See original GitHub issue

Conceptually, I like to think of a breakpoint as a threshold value. If the breakpoint value is 500px I would expect an above query to be >500px and a below query to be <500px.

In the example:

{
  sm: '576px',
  md: '768px',
  lg: '992px',
  xl: '1200px',
}

up('md') => '@media (min-width: 768px) { ... }'
only('md') => '@media (min-width: 768px) and (max-width: 991.98px) { ... }'
down('md') => '@media (max-width: 991.98px) { ... }'
between('md', 'lg') => '@media (min-width: 768px) and (max-width: 1199.98px) { ... }'

up('md') makes complete sense as being greater than or equal to md.

only('md') also makes total sense as selecting [md, lg).

down('md') I don’t agree with, as it seems like it should be <md. Instead, it is <lg.

between('md', 'lg') follows this same logic as down, querying from [md, xl), when I would prefer[md, lg)

As this is currently written, there is no way to select down() from the lowest breakpoint, which is often the most useful breakpoint, as things are most likely to break the layout at this extreme value. down('xs') is currently interpreted as <Sm (not <Xs).


Proposed solution:

The names for this new query could be downFrom or upTo.

downFrom('md') => '@media (max-width: 767.8px) { ... }'
upTo('md') => '@media (max-width: 767.8px) { ... }'

Alternatively, down('md', orientation, true) could use a third argument to specify the max-width of md rather than the next higher breakpoint (lg). Renaming calcMinWidth -> getWidthAtBreakpoint and calcMaxWidth -> getWidthAtNextBreakpoint also helps to clarify the functionality.

Here’s a feature proposal of how the latter could look with 3 additional unit tests: https://github.com/iRyanBell/styled-breakpoints/tree/feat/is-below-break-proposal

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

3reactions
iRyanBellcommented, Nov 22, 2020

@iRyanBell maybe these videos will help you think mobile first. video book

Bootstrap Снимок экрана 2020-11-22 в 12 36 33

Zurb Foundation Снимок экрана 2020-11-22 в 12 37 27

I’m totally on board with a mobile-first mindset for cascading styles by additive viewport width.

My complaint here was largely around the naming convention of up(Md) meaning “greater than the ‘md’ width definition”, while down(Md) translates non-symmetrically to “less than next higher definition after ‘md’” – I get the logic behind this model, seeing breakpoints as ranges, but I would prefer a more precise interpretation.

1reaction
mg901commented, Nov 22, 2020

@iRyanBell maybe these videos will help you think mobile first. video book

Bootstrap Снимок экрана 2020-11-22 в 12 36 33

Zurb Foundation Снимок экрана 2020-11-22 в 12 37 27

Read more comments on GitHub >

github_iconTop Results From Across the Web

Range Selectors in FlexChart - Wijmo Docs - GrapeCity
Range selectors allow users to zoom in on selected parts of a chart by selecting a range on a secondary chart. The most...
Read more >
Adding an additional range selector - After Effects Video Tutorial
What are they? In this video, Luisa Winters demonstrates how to add additional range selectors when animating text in Adobe After Effects.
Read more >
Range selector - Highcharts
The range selector is a tool for selecting ranges to display within the chart. It provides buttons to select pre-configured ranges in the...
Read more >
CSS | :in-range Selector - GeeksforGeeks
The :in-range selector is used to selecting all elements that are given within a particular range value. It is mostly used in an...
Read more >
Using CSS Mod Queries with Range Selectors - A List Apart
As with mod query, there isn't a native CSS range selector, but we can create one by combining two selectors: :nth-child(n) (i.e., “everything ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found