Use a container query. The cqw
unit represents 1% of the item's width. You can use that unit in your calc()
function.
I made the item resizable in the following demo, to make the functionality easier to observe.
.container {
container-type: inline-size;
background: #ddd;
/* Make resizable, for demo purposes */
resize: horizontal;
overflow: hidden;
}
.item {
background: orange;
}
@container (min-width: 0) {
.item {
/* 50% of container width + 30px */
height: calc(50cqw + 30px);
}
}
<div class="container">
<div class="item">Resize me!</div>
</div>
Note that, as of 2022, container queries are very new and not supported in all browsers. Modern Chrome and Safari are supported, though.