I am trying to figure out how to solve the following problem with CSS:
I have a container, say it's a div. It should be always visible on my page, vertically and horizontally centered. The container should not have a fixed size, but a fixed proportion (or aspect ratio), say: "width = 1/3 of height". Moreover, the container should be always visible as huge as possible. (Meaning either "touch" the upper and lower OR the left and right borders of the browser window, depending on the current window size)
This is how I proceeded so far:
relevant html:
<body>
<div>Text</div>
</body>
css:
body {
margin: 0px;
}
div {
position: absolute;
background-color: red;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
This of course only centers the div. The cucial part is the sizing, that I described above. Would this be possible with css?