Du kannst es mit CSS Variablen und Javascript versuchen.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
.container {
display: flex;
align-items: center;
justify-content: center;
height: 200px;
background-color: lightgray;
}
.dynamic-element {
width: var(--dynamic-width, 50%); /* Use a CSS variable as the default width */
height: 100%;
background-color: orange;
}
</style>
<script>
const container = document.querySelector('.container');
const dynamicElement = document.querySelector('.dynamic-element');
// Update the --dynamic-width CSS variable with the container's width
dynamicElement.style.setProperty('--dynamic-width', container.offsetWidth * 0.5 + 'px');
</script>
</head>
<body>
<div class="container">
<div class="dynamic-element"></div>
</div>
</body>
</html>