unit-vh-vw-overflow-scroll-y-ref-iframe.html 950 B

1234567891011121314151617181920212223242526272829
  1. <style>
  2. body { overflow-y: scroll }
  3. div {
  4. width: 10px;
  5. height: 10px;
  6. background-color: #d64203;
  7. }
  8. </style>
  9. <body>
  10. <div id="a"></div>
  11. <div style="height: 50px"></div> <!-- Unaffected by scrollbars. -->
  12. <div id="c"></div>
  13. <div style="height: 50px"></div> <!-- Unaffected by scrollbars. -->
  14. <!-- Deliberately make scrollbars appear. -->
  15. <div style="width: 500px; height: 500px; background-color: black">
  16. </body>
  17. <script>
  18. // client{Width, Height} consist of the area _inside_ the scrollbars, so these
  19. // manually calculated units reflect the fact that with 'overflow: scroll' set,
  20. // viewport units are sized taking the scrollbars into account. Since we're
  21. // only dealing with 'overflow-y' here, only the width units are affected.
  22. var vw = 0.01 * document.body.clientWidth;
  23. document.getElementById('a').style.width = (50 * vw) + "px";
  24. document.getElementById('c').style.width = (35 * vw) + "px";
  25. </script>