I have a div with this css rule:
.somediv {
aspect-ratio: 1 / 3 !important;
}
I want to make the height equal not exactly (3 * width), but plus 8 pixels. For example, if my width is 10px, the height have to be like (10*3)+8 = 38 pixels. How can i do this, i know about calc() in css, but not sure it works with aspect-ratio.
>Solution :
If you are to set a fixed width , you may use CSS var() to set the width, then use calc() for aspect-ratio
examples
:root {
--width: 80;
}
div {
margin: 1em;
border: solid;
width: calc(var(--width) * 1px);
aspect-ratio: var(--width) / calc(var(--width) * 3 + 8);
/* demo purpose */
float: left;
}
div:before{
content:attr(style);
<div>défault</div>
<div style="--width:100"> </div>
<div style="--width:101"> </div>
<div style="--width:70"> </div>
<div style="--width:90"> </div>
If width is not, then javascriipt will be required