Jump to content

Container based clamping


gornycreative
 Share

Recommended Posts

Hello friends,

I was playing around with the clamp techniques used to provide progressive font sizing, and it has replaced flowtype.js in most projects.

But one of the things that I really missed was the ability to scale based on container width - rather than full viewpoint width. I was also interested in trying to replace fittext.js and learned a very useful technique with reasonable browser support:

https://codepen.io/solonmg/pen/ZEwGEay

instead of using vw units, you can apply:

container-type: size;
container-type: inline-size;

And then by dividing the character count of a line by 100 and applying the outcome to use cqw units instead of vw units, you get the same scaling type features.

If you are trying to get that optimal character/word line length in a given column, this will certainly help! The same clamping limits that already exist based on viewport widths work for containers.

I don't know if it makes sense to have separate clamping settings for display text (like headings) and body text, but this is just something I have been playing around with.

  • Like 4
Link to comment
Share on other sites

I'm aware of container queries being something coming in the future but I thought it's not there yet or at least not well enough supported to be used just now. Let me know if I'm wrong and I'm happy to add support for it if that's possible.

I think rfGrow() is a great helper and I'm happy that it's useful for you as well 🙂 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...