How to make the home page of the web page dynamically adjust the page media?

62 Views Asked by At

I'm using page media to define the home page of the web page, but it can't be dynamically adjusted, it can only be adjusted before each rendering, which is very inconvenient

here is the css code:

.test-matter {
  page: matter;
}
@page matter{
  margin-top: 20mm;
  margin-right: 15mm;
  margin-bottom: 20mm;
  margin-left: 15mm;
}

But it only seems to apply the default page media settings , each side is margin 25mm

1

There are 1 best solutions below

0
On

You can use JavaScript for making this easier. If you use the onresize="myFunction()" your function will be called every time you change window size.Just add the following:

JavScript

<script>
function myFunction() {
   // Your code here
}
</script>

HTML

<body onresize="myFunction()">
    <!-- HTML here -->
</body>

You can use css in the function, to dynamically change it.