Skip to content
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

✨ Container Queries #334

Open
1aron opened this issue Mar 14, 2024 · 6 comments
Open

✨ Container Queries #334

1aron opened this issue Mar 14, 2024 · 6 comments
Labels
feature New feature
Milestone

Comments

@1aron
Copy link
Member

1aron commented Mar 14, 2024

Description

Too many people have asked about this feature, and here is the proposal of Master CSS 2.X Container Queries.

Applying styles based on a container's size

<div class="container:inline-size">
    <div class="font:32@container<=600">
        <h2>Card title</h2>
        <p>Card content</p>
    </div>
</div>

Generated CSS

.container\:inline-size {
    container-type: inline-size
}

@container (max-width: 600px) {
    .font\:32\@container\<\=600 {
        font-size: 2rem
    }
}

Creating named container contexts

We intend to fallback any unknown at tokens to container names.

<div class="container:post/inline-size">
    <div class="font:32@post<=600">
        <h2>Card title</h2>
        <p>Card content</p>
    </div>
</div>

Generated CSS

.container\:post\/inline-size {
    container: post / inline-size
}

@container post (max-width: 600px) {
    .font\:32\@post\<\=600 {
        font-size: 2rem
    }
}
@1aron 1aron added the feature New feature label Mar 14, 2024
@1aron 1aron added this to the 2.X milestone Mar 14, 2024
@MarkSky
Copy link

MarkSky commented Mar 15, 2024

<div class="font:32@container<=600">
        <h2>Card title</h2>
        <p>Card content</p>
</div>

How to know @container<=600 is height or width?

@1aron
Copy link
Member Author

1aron commented Mar 15, 2024

<div class="font:32@container<=600">
        <h2>Card title</h2>
        <p>Card content</p>
</div>

How to know @container<=600 is height or width?

As responsive breakpoints currently only support width, specifying height may require writing a full CSS query.

<div class="container:inline-size">
    <div class="font:32@container(min-height:600px)">
        <h2>Card title</h2>
        <p>Card content</p>
    </div>
</div>

@moaali
Copy link

moaali commented Mar 16, 2024

@1aron Just throwing a different shorter syntax for defining the container which I'm currently using:

rules: {
  '@container': {
    match: /^@container/,
    declare(value) {
      let [name = '', type = 'inline-size'] = value.split('/');

      name && (name = `${name} / `);

      return {
        container: name + type
      };
    }
  }
}

inline-size is chosen as the default value as it covers 99% of the use cases, and I use it like below:

<div class="@container" />               // container: inline-size 
<div class="@container:sidebar" />       // container: sidebar / inline-size 
<div class="@container:sidebar/size" />  // container: sidebar / size 

and here is a different way for using the queries on the child elements that you might consider, like the following

@container/sidebar<=600      // for parent container named sidebar and <= 600px
@container/sidebar<=600|h    // for parent container named sidebar and HEIGHT <= 600px

@1aron
Copy link
Member Author

1aron commented Mar 16, 2024

@moaali Looks good! @ represents CSS at-rules in Master CSS syntax, writing container:sidebar/size directly should avoid confusion.

@MarkSky
Copy link

MarkSky commented Mar 18, 2024

<div class="font:32@container<=600">
        <h2>Card title</h2>
        <p>Card content</p>
</div>

How to know @container<=600 is height or width?

As responsive breakpoints currently only support width, specifying height may require writing a full CSS query.

<div class="container:inline-size">
    <div class="font:32@container(min-height:600px)">
        <h2>Card title</h2>
        <p>Card content</p>
    </div>
</div>

I think use font:32@container(min-h:600px) is better than font:32@container(min-height:600px)

@neneodonkor
Copy link

This feels like media queries or css breakpoints

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature
Projects
None yet
Development

No branches or pull requests

4 participants