I'm trying to change element's opacity based on how wide the browser's window is in a continuous manner. Ideally, I would like to get a unit-less value from calc by dividing current viewport's width by some constant, like this:
opacity: clamp(0.5, calc(100vw / 1000px), 1);
but calc doesn't allow dividing by a unit. Is there any other way to achieve this in CSS?
Unless you define some default opacities for different breakpoints using media queries I think you'd have to rely on js to achieve this. Seems like it is not possible to strip units in CSS unfortunately.
I was playing around with this in different ways and this was the closest behavior I could get:
Note: This is definitely not the best way to change opacity dynamically using js!