New calc-size() function for intrinsic size keywords

🧐 Did you know you can now perform calculations on intrinsic size keywords like max-content? ❌ No JavaScript needed For years, web developers have faced a frustrating limitation: you couldn't use intrinsic size keywords like auto or min-content inside the calc() function. This meant complex workarounds, often involving JavaScript, for what should have been simple layout adjustments. Well, not anymore! The new calc-size() function is here to fix that. It allows you to perform calculations directly with these intrinsic values. This unlocks a new level of flexibility for creating dynamic and responsive components. How it works: The Syntax: property: calc-size(<calc-size-basis>, <calc-sum>); Imagine you need a container to be its max-content width plus a little extra padding: width: calc-size(max-content, size + 2rem); The size keyword acts as a variable for your basis (max-content in this case). Here are a few more examples: 🔹 Resolve to an auto value: width: calc-size(auto, size); 🔹 Nest other functions: width: calc-size(auto, round(up, size, 50px)); 💡 Quick Tip: If you only need to animate or transition between sizes without a calculation, check out interpolate-size: allow-keywords; instead. Read More: https://lnkd.in/dANGC2jC 𝗡𝗼𝘁𝗲 𝗼𝗻 𝗯𝗿𝗼𝘄𝘀𝗲𝗿 𝘀𝘂𝗽𝗽𝗼𝗿𝘁: This is a very new feature and still has limited support. As of now, it's available in Chrome 130+ and is on its way to other browsers. caniuse: https://lnkd.in/ds95GFW4) Reference articles: https://lnkd.in/dNiFay2J https://lnkd.in/dPhJc6Xn This is a fantastic step forward for native CSS capabilities. What's the first layout problem you'd solve with this? #CSS #CSSFunctions #WebDevelopment #Frontend #CodingTips #WebDesign #WebDev #DeveloperTips #itsmacr8

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories