Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • B bootstrap
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 263
    • Issues 263
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 114
    • Merge requests 114
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Bootstrap
  • bootstrap
  • Merge requests
  • !37752

v6: Test out using `postcss-custom-media` to reduce responsive variants

  • Review changes

  • Download
  • Email patches
  • Plain diff
Open Mark Otto requested to merge v6-postcss-custom-media into main Dec 29, 2022
  • Overview 0
  • Commits 1
  • Pipelines 0
  • Changes 3

Had an idea tonight—can we build a single responsive variant for say the navbar expand that can be customized via CSS variable? Well the answer is not quite. This is because we cannot use CSS variables in media queries. However, we can generate custom media queries and then override those with the help of postcss-custom-media.

Here's how it looks in this proof of concept PR:

@custom-media --navbar-expand (min-width: 768px);

@media (--navbar-expand) {
  .new-navbar-expand {
    // styles
  }
}

You can then override the --navbar-expand custom media:

@custom-media --navbar-expand (min-width: 992px);

Together with PostCSS, this generates the normal media query: @media (min-width: 992px) { ... }. It adds a dependency, but holy crap could it clean out some duplicate code for responsive media queries. This could most obviously work well on our navbar and offcanvas components, but it'd also work on the responsive list groups, dropdown menus, and responsive tables.

Or it could all be a waste. Either way, fun to play around with the idea.

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: v6-postcss-custom-media