Skip to content

Using container as custom media queries #557

Description

@AlessioCoser

Do you see any problem handling custom media queries without the need of postcss preprocessor?

I thought something like this could do:

:root {
    --is-below-xxs: false;
    --is-below-xs: false;
    --is-below-sm: false;
    --is-below-md: false;
    --is-below-lg: false;
    --is-below-xl: false;
    --is-below-xxl: false;

    @media screen and (max-width: 240px) {
        --is-below-xxs: true;
    }
    @media screen and (max-width: 360px) {
        --is-below-xs: true;
    }
    @media screen and (max-width: 480px) {
        --is-below-sm: true;
    }
    @media screen and (max-width: 768px) {
        --is-below-md: true;
    }
    @media screen and (max-width: 1024px) {
        --is-below-lg: true;
    }
    @media screen and (max-width: 1440px) {
        --is-below-xl: true;
    }
    @media screen and (max-width: 1920px) {
        --is-below-xxl: true;
    }
}

Usage:

@container style(--is-below-xxs: true) {
    /* ... */
}

I've checked the browser compatibility, and it seems fine: https://caniuse.com/?search=%40container

What do you think? I can try to make a pull request if you think it would be a good fit for the project.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions