Applying a conditional border-radius in CSS (without media queries)

šŸ“– Neural networks for Javascript developers

The Neural Networks for JavaScript developers book is almost ready! Learn the basics of AI with TensorFlowJs examples. Join now the presale and get a 15$ coupon off the launching price!

Starting from a curiosity seen on the Facebook CSS Ahmad Shadeed wrote a great article explaining how to change the border-radius without using any media queries at all.

The magic CSS formula is:

border-radius: max(0px, min(8px, calc((100vw - 4px - 100%)
    * 9999)));

Basically, it uses the min() and max() functions combined with the calc() function to conditionally set a border radius of 0px or 8px.

While it is a super cool study case of what we can do these days with functions in CSS, I find it to be a bit hard to read. A bit too smart maybe :). For sure it's a very elegant technical solution, and could be also a cool trick to impress colleagues, but if possible I would choose a more readable solution.

By the way, another function that could be used to change elements based on the size is the minmax function.

šŸ“– Neural networks for Javascript developers

The Neural Networks for JavaScript developers book is almost ready! Learn the basics of AI with TensorFlowJs examples. Join now the presale and get a 15$ coupon off the launching price!


Leave a Reply

Your email address will not be published. Required fields are marked *

Home Screencasts Best of Newsletter Search X

Neural Networks for JavaScript developers
Presale - 15$ free coupon

Hi friend! Before you go, just wanted to let you know that in March 2023 I will be launching the TensorFlow.Js by Example course.

This course will include basic concepts of AI and Neural Networks done with TensorFlowJs such as:

  • Working with datasets
  • Visualizing training
  • Deep Neural Networks in JavaScript
  • Reinforcement Learning
  • Convolutional neural networks
  • and much more ...

Also, there will be a lot of examples as:

  • Object detection
  • Natural language processing
  • Face and voice recognition
  • Gaming AI

Join now the waiting list and get a 15$ coupon off the launching price!

X