Skip to content

Add variants support to container plugin #2032

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

Merged
merged 2 commits into from
Jul 15, 2020
Merged

Conversation

adamwathan
Copy link
Member

This PR adds variants support to the container plugin, allowing you to generate responsive variants (like md:container) or even pseudo-class variants (like hover:container, which is a terrible idea but it's a free country.)

I've enabled responsive variants for the container by default, which closes #1964.

One less than ideal thing about the current implementation is that it generates some unreachable CSS:

@media (min-width: 1280px) {
  .xl\:container {
    width: 100%
  }

  /* This is unreachable */
  @media (min-width: 640px) {
    .xl\:container {
      max-width: 640px
    }
  }

  /* This is unreachable */
  @media (min-width: 768px) {
    .xl\:container {
      max-width: 768px
    }
  }

  /* This is unreachable */
  @media (min-width: 1024px) {
    .xl\:container {
      max-width: 1024px
    }
  }

  @media (min-width: 1280px) {
    .xl\:container {
      max-width: 1280px
    }
  }
}

I think it's worth it to avoid introducing a lot of extra complexity, but we might consider adding another optimization later on that is able to remove dead code like this.

@adamwathan adamwathan merged commit 50de485 into master Jul 15, 2020
@zzwx
Copy link

zzwx commented Jul 30, 2020

What I mean is, does the above nesting code do anything more than what this CSS does:

.container {
  width: 100%
}
@media (min-width: 640px) {
  .container,
  .sm\:container {
    max-width: 640px
  }
}
@media (min-width: 768px) {
  .container,
  .md\:container {
    max-width: 768px
  }
}
@media (min-width: 1024px) {
  .container,
  .lg\:container {
    max-width: 1024px
  }
}
@media (min-width: 1280px) {
  .container,
  .xl\:container {
    max-width: 1280px
  }
}

@browner12
Copy link
Contributor

Thank you for adding responsive containers to Tailwind. However, after using it and looking through the generated CSS, it does not appear to be behaving as expected. Since there is a media query that wraps the whole thing, the containers are losing their margin and padding at widths below the breakpoint. That means, for example, that md:container is receiving the margin and padding above the 768px breakpoint, but losing them below that breakpoint. This inconsistency makes it very difficult to use the responsive containers.

I was the original author of responsive containers on Bootstrap. Here are the relevant PRs.

twbs/bootstrap#25631
twbs/bootstrap#29118

I'm making the assumption we want the Tailwind responsive containers to behave the same, so if I'm wrong on that, let me know.

Here is the CSS we desired to generate (with some tweaks to bring it closer to Tailwind):

.container,
.sm:container,
.md:container,
.lg:container,
.xl:container {
  width: 100%;
  padding-right: theme('container.padding');
  padding-left: theme('container.padding');
  margin-right: auto;
  margin-left: auto;
}

@media (min-width: 640px) {
  .container,
  .sm:container {
    max-width: 640px;
  }
}

@media (min-width: 768px) {
  .container,
  .sm:container,
  .md:container {
    max-width: 768px;
  }
}

@media (min-width: 1024px) {
  .container,
  .sm:container,
  .md:container,
  .lg:container {
    max-width: 1024px;
  }
}

@media (min-width: 1280px) {
  .container,
  .sm:container,
  .md:container,
  .lg:container,
  .xl:container {
    max-width: 1280px;
  }
}

I am more than willing to help update this, but I am much more familiar with writing SASS than how Tailwind does it with JS, so I just need some direction on that.

@zzwx
Copy link

zzwx commented Aug 5, 2020

@browner12 , I don't think @adamwathan sees this closed merge. May be you need to open a new issue.

@browner12
Copy link
Contributor

yah, that's the feeling I was getting.

good idea.

@adamwathan adamwathan deleted the container-variants branch August 15, 2020 22:08
workashutosh pushed a commit to workashutosh/tailwindcss that referenced this pull request Apr 3, 2025
The documentation says to use the `--font-*` theme variables to
customize the font weight utilities in your project:

<img width="737" alt="image"
src="https://github.com/user-attachments/assets/523330ea-f98d-4694-8fdb-ee0454211008"
/>

But for `---font-800: 800` that actually creates a `font-family: 800`
rule instead of the intended `font-weight: 800` one.

The "Theme variables namespace" is mentioning the correct
`--font-weight-*` one:
https://tailwindcss.com/docs/theme#theme-variable-namespaces
thecrypticace added a commit that referenced this pull request Jun 5, 2025
Here is everything you need to know about this upgrade. Please take a
good look at what changed and the test results before merging this pull
request.

### What changed?




#### ✳️ postcss (8.5.3 → 8.5.4) ·
[Repo](https://github.com/postcss/postcss) ·
[Changelog](https://github.com/postcss/postcss/blob/main/CHANGELOG.md)



<details>
<summary>Release Notes</summary>
<h4><a
href="https://github.com/postcss/postcss/releases/tag/8.5.4">8.5.4</a></h4>

<blockquote><ul dir="auto">
<li>Fixed Parcel compatibility issue (by <a
href="https://bounce.depfu.com/github.com/git-sumitchaudhary">@git-sumitchaudhary</a>).</li>
</ul></blockquote>
<p><em>Does any of this look wrong? <a
href="https://depfu.com/packages/npm/postcss/feedback">Please let us
know.</a></em></p>
</details>

<details>
<summary>Commits</summary>
<p><a
href="https://github.com/postcss/postcss/compare/22c309d32924e1eeb33c80a6a50b7ba8a43a1832...6cb4a6673fb6d8b23eb1ebe66a22b6267ab141de">See
the full diff on Github</a>. The new version differs by 23 commits:</p>
<ul>
<li><a
href="https://github.com/postcss/postcss/commit/6cb4a6673fb6d8b23eb1ebe66a22b6267ab141de"><code>Release
8.5.4 version</code></a></li>
<li><a
href="https://github.com/postcss/postcss/commit/ec5c1e031083664bed1cf91eaac72f8c61068110"><code>Update
dependencies</code></a></li>
<li><a
href="https://github.com/postcss/postcss/commit/e85e9385c87499bc7e274c6ce332cf59e3988994"><code>Fix
code format</code></a></li>
<li><a
href="https://github.com/postcss/postcss/commit/50542335f22e513edaa52cb8bd214370ceef1bc9"><code>fixed
error at line 401 (#2046)</code></a></li>
<li><a
href="https://github.com/postcss/postcss/commit/0538b6309e5ca80044bc8ca34833db422bbaa9fe"><code>docs:
Update README.md (#2044)</code></a></li>
<li><a
href="https://github.com/postcss/postcss/commit/b5f407f3976419310bcc530043f5835b7192f41c"><code>Add
`postcss-fontsource-url` to plugins (#2043)</code></a></li>
<li><a
href="https://github.com/postcss/postcss/commit/94b5260be6fd43f230cc4dd91a7d3c51b09a0e94"><code>Clarify
documentation for `node.source.end.offset` (#2032)</code></a></li>
<li><a
href="https://github.com/postcss/postcss/commit/a20724af14ad05304f99ced858f6f2f47f4a1633"><code>Fix
Markdown syntax</code></a></li>
<li><a
href="https://github.com/postcss/postcss/commit/cf6b9697519aa0a9feda3b3468a738ba8870b61b"><code>fix:
add a mention for postcssense extension (#2040)</code></a></li>
<li><a
href="https://github.com/postcss/postcss/commit/ff48c29ebb16339188761827701e832f516bfb7d"><code>Increase
size</code></a></li>
<li><a
href="https://github.com/postcss/postcss/commit/f82c2a60906ee889be26fe8e7e37d90fca23224e"><code>Add
`Input#fromLineAndColumn`, `CssSyntaxError.input.offset` and
`CssSyntaxError.input.endOffset` (#2034)</code></a></li>
<li><a
href="https://github.com/postcss/postcss/commit/7892a29ff8492f11cf2ce07f9aa17def26f96338"><code>Fix
missing offset in `Node#positionInside`, `Node#positionBy` and
`Node#rangeBy` (#2033)</code></a></li>
<li><a
href="https://github.com/postcss/postcss/commit/875f1fb7f863a859d16261b0a24a5823e7a6c40d"><code>Fix
`opts` argument of `Node#rangeBy()` and `Node#positionBy()` cannot be
omitted (#2031)</code></a></li>
<li><a
href="https://github.com/postcss/postcss/commit/25443a59303678426e521fdb434bf95f4925ca14"><code>Update
dependencies</code></a></li>
<li><a
href="https://github.com/postcss/postcss/commit/0a76df5f60511cb577374f869942e5a52d976666"><code>add
postcss-auto-var-fallback fallback plugin to plugins.md
(#2026)</code></a></li>
<li><a
href="https://github.com/postcss/postcss/commit/3fc6388e91d496105f5a8fe63ab22a9a5a3c5254"><code>Update
Nano ID</code></a></li>
<li><a
href="https://github.com/postcss/postcss/commit/368bd0092000f01f6e873d9f55ef3c93a9149217"><code>Change
in type definition of property `css` of `result` (#2025)</code></a></li>
<li><a
href="https://github.com/postcss/postcss/commit/9229218b515eaffcd6f5c6bacdee766f27262ebc"><code>Update
dependencies</code></a></li>
<li><a
href="https://github.com/postcss/postcss/commit/6c2a808c4ac483317be2a906b5ee6d168a16568c"><code>Clean
up code</code></a></li>
<li><a
href="https://github.com/postcss/postcss/commit/31a5de71d12f16aa31092c86106cd6f181bd1250"><code>Return
type of method `raw` of `Stringifier` can be boolean, as the property
`semicolon` can be boolean (#2024)</code></a></li>
<li><a
href="https://github.com/postcss/postcss/commit/c5058912f2659f2c81ec7ccf04408fd4f25e4fc0"><code>There
are no other `props` with non-string type.</code></a></li>
<li><a
href="https://github.com/postcss/postcss/commit/a9cf39e7fe864e87d91d56511fd594a0dc0fbdf5"><code>The
return type of the method rawValue in Stringifier should be `any`
instead of `string`</code></a></li>
<li><a
href="https://github.com/postcss/postcss/commit/7ac43db0c30c08dc799a55e5f2f1f269a61b6856"><code>Update
ESLint config</code></a></li>
</ul>
</details>












---
![Depfu
Status](https://depfu.com/badges/edd6acd35d74c8d41cbb540c30442adf/stats.svg)

[Depfu](https://depfu.com) will automatically keep this PR
conflict-free, as long as you don't add any commits to this branch
yourself. You can also trigger a rebase manually by commenting with
`@depfu rebase`.

<details><summary>All Depfu comment commands</summary>
<blockquote><dl>
<dt>@​depfu rebase</dt><dd>Rebases against your default branch and
redoes this update</dd>
<dt>@​depfu recreate</dt><dd>Recreates this PR, overwriting any edits
that you've made to it</dd>
<dt>@​depfu merge</dt><dd>Merges this PR once your tests are passing and
conflicts are resolved</dd>
<dt>@​depfu cancel merge</dt><dd>Cancels automatic merging of this
PR</dd>
<dt>@​depfu close</dt><dd>Closes this PR and deletes the branch</dd>
<dt>@​depfu reopen</dt><dd>Restores the branch and reopens this PR (if
it's closed)</dd>
<dt>@​depfu pause</dt><dd>Ignores all future updates for this dependency
and closes this PR</dd>
<dt>@​depfu pause [minor|major]</dt><dd>Ignores all future minor/major
updates for this dependency and closes this PR</dd>
<dt>@​depfu resume</dt><dd>Future versions of this dependency will
create PRs again (leaves this PR as is)</dd>
</dl></blockquote>
</details>

Co-authored-by: depfu[bot] <23717796+depfu[bot]@users.noreply.github.com>
Co-authored-by: Jordan Pittman <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

implementation of md:container would be helpfull
4 participants