A need a div to be responsive, to maintain its aspect ratio and to
always be completely visible within the viewport.
A search turned up CSS like this
#wrap {
width: 100%;
display: inline-block;
position: relative;
}
#wrap::after {
padding-top: 56.25%; /* 16:9 ratio */
display: block;
content: '';
}
#editor {
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
}
with this HTML
<div id="wrap">
<div id="editor">
<p>Hello World!</p>
</div>
</div>
Alas it only works so long as ratio of the browser window is bigger
than, in this case, 16:9.
That is, when the browser window isn't tall enough I get scrollbars.
Ideally wrap's height (and width) should shrink to so that wrap never
extends beyond the viewport. How is this possible in CSS?
I solved it but I had to write some JavaScript to do it. If one could
use CSS variables within @media eg
@media screen and (max-width: var(--num) { }
then it may have been easier.
On 9/11/2020 9:30 am, Andrew Poulos wrote:
A need a div to be responsive, to maintain its aspect ratio and to
always be completely visible within the viewport.
A search turned up CSS like this
with this HTML
Alas it only works so long as ratio of the browser window is
bigger than, in this case, 16:9.
That is, when the browser window isn't tall enough I get
scrollbars. Ideally wrap's height (and width) should shrink to so
that wrap never extends beyond the viewport. How is this possible
in CSS?
I solved it but I had to write some JavaScript to do it. If one
could use CSS variables within @media eg
@media screen and (max-width: var(--num) { }
then it may have been easier.
In Message: <hPadnTpyM_QHETbCnZ2dnUU7-ffNnZ2d@westnet.com.au>
Andrew Poulos <ap_prog@hotmail.com> wrote:
On 9/11/2020 9:30 am, Andrew Poulos wrote:
A need a div to be responsive, to maintain its aspect ratio and to
always be completely visible within the viewport.
A search turned up CSS like this
[snip]
with this HTML
[snip]
Alas it only works so long as ratio of the browser window is
bigger than, in this case, 16:9.
That is, when the browser window isn't tall enough I get
scrollbars. Ideally wrap's height (and width) should shrink to so
that wrap never extends beyond the viewport. How is this possible
in CSS?
I solved it but I had to write some JavaScript to do it. If one
could use CSS variables within @media eg
@media screen and (max-width: var(--num) { }
then it may have been easier.
https://codepen.io/noneyainvalid/full/WNxYXZo
perhaps with @media (min-aspect-ratio: 16/9) to calculate the ratio
based from the height.
Default to calculate the ratio based from the width.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 294 |
Nodes: | 16 (2 / 14) |
Uptime: | 244:25:53 |
Calls: | 6,626 |
Calls today: | 2 |
Files: | 12,175 |
Messages: | 5,320,390 |