tailwindcss-container-queries: Missing support for core-supported dynamic breakpoints

What version of @tailwindcss/container-queries are you using?

v0.1.1

What version of Node.js are you using?

v18.16.0

What browser are you using?

Chrome v112.0.5615.137

What operating system are you using?

macOS v13.1 (22C65)

Tailwind Play Reproduction

https://play.tailwindcss.com/iyNosSvgd1

Describe your issue

Purpose / Problem

There currently exists no way AFAIK to use the dynamic breakpoints functionality newly introduced in TailwindCSS v3.2, or anything comparable when it comes to container queries.

There is this arbitrary syntax supported: @[17.5rem]:underline however…

  • no max- equivalent exists
  • the syntax for this departs a bit from the core non-container-related implementation of min-*

Proposed Solution

It might be helpful to follow the core implementation’s lead by adding support for min-* and max-* dynamic breakpoints for arbitrary values:

<div class="@container grid h-screen w-screen">
  <div class="bg-[red] @min-[1px]:bg-[green]"></div>
  <div class="bg-[red] @max-[1px]:bg-[green]"></div>
</div>

This way, it works identically to the core implementation but is prepended with @, which is already being used by this plugin to denote container-related queries.

Support for width/height distinction

Furthermore, per a related PR to the core implementation to add support for an explicit w:/h: prefix to the arbitrary value to determine the dimension (e.g. min/max-width/height), implementing the same pattern could be helpful here if that PR passes, which could work like this:

<!--
  `w:` is implied when no `w:`/`h:` prefix is specified,
  but it can also be included explicitly, optionally
-->
<div class="@min-[h:100px]:@max-[100px]:font-bold" />

Syntax consideration

It may be worth considering which of these syntaxes makes more sense in line with the core implementation:

@ before min/max

(as shown above)

  • @min-[1px]:
  • @min-[w:1px]:
  • @min-[h:1px]:
  • @max-[100vw]:
  • @max-[w:100vw]:
  • @max-[h:100vw]:

@ before […]

(as shown above)

  • min-@[1px]:
  • min-@[w:1px]:
  • min-@[h:1px]:
  • max-@[100vw]:
  • max-@[w:100vw]:
  • max-@[h:100vw]:

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 23
  • Comments: 16 (1 by maintainers)

Most upvoted comments

Hi @christian-wantia, thanks! If you want to take a stab at it, and have any questions along the way, let me know.

I would recommend using my related PR (https://github.com/tailwindlabs/tailwindcss/pull/11225) as a guide, as it does the same operation we’re striving for here but for media queries.

Some notes / gotchas

  • 🚨 Avoid those alternative syntaxes you mentioned like @max-h-2xl as that syntax wouldn’t work for the core media queries, since max-h is already a dedicated utility for max-height CSS property, and the heart of this issue is to align the two.

    Let’s stick with the optional w:/h: modifier. 🙂

  • It’s also crucial that the container queries are sorted in the correct order, same as the sorting for the core container queries, so they should always be sorted as (no modifier), w:, h:, and each respective group being sorted in ascending/descending order accordingly (order flipped for max vs. min queries).

Thanks again for contributing here! I really appreciate it. Let me know how I can help.