For examples of a javascript attempt see end of question
I am trying to create the illusion of working on an A4 document inside of an HTML application and would like to scale my A4 pages to their parent element's size using only CSS. When the parent element gets smaller because (for example) the browser is scaled I want the content to remain with the same proportions but smaller, scaled to fit the parent.
A pure CSS solution would have my preference, but if there is no other way I wouldn't mind using JavaScript to measure the parent's dimensions and scale the child to fit.
Example code in JS:
var page = document.getElementsByClassName("page")[0];
var scaleX = page.parentElement.clientWidth / page.clientWidth;
if (scaleX < 1) {
page.setAttribute("style", `transform:scale(${scaleX});`);
}
My styling currently is the following:
.page-container {
height: 7cm;
width: 6cm;
border: 1px solid black;
overflow-x: hidden;
overflow-y: auto;
padding: 1rem;
background: orange;
display: flex;
flex-direction: column;
resize: both;
align-items: center;
justify-content: flex-start;
align-content: flex-start;
}
.page {
min-height: 29.7cm !important;
max-height: 29.7cm !important;
height: 29.7cm !important;
width: 21cm !important;
background: white;
padding: 21mm;
border: 1px solid gray;
}
An example of the JS version can be found here, I can't figure out how to remove the whitespace around the page elements.
