首页 > 其他 > 详细

页面内容如何随窗口(宽度)的改变而改变大小?

时间:2019-09-24 15:02:37      阅读:658      评论:0      收藏:0      [点我收藏+]

效果图:

图一:

技术分享图片

 

 图二:

技术分享图片

 

 代码:<!DOCTYPE html<html lang="en"><head>

    <meta charset="UTF-8">
    <title></title>
    <link type="text/css" rel="stylesheet" href=" "/>
    <style type="text/css">
        * {
            margin: 0;
            padding: 0;
       font-size: 0.12rem;
     } #float{ width: 2rem; height: 2rem; border: 0.01rem solid black; } #float div{ width: 0.4rem; height: 0.4rem; float: left; } #float .one{ background-color: blue; } #float .two{ background-color: green; } #float .three{ background-color: red; } #float .four{ background-color: yellow; } </style> </head> <body> <div id="float"> <div class="one"></div> <div class="two"></div> <div class="three"></div> <div class="four"></div> </div> <script type="text/javascript"> window.onload = function () { // 获取浏览器页面最大宽度 var maxWidth = document.documentElement.offsetWidth document.documentElement.style.fontSize = document.documentElement.offsetWidth/(maxWidth/100) + px; window.onresize = function(){ document.documentElement.style.fontSize = document.documentElement.offsetWidth/(maxWidth/100) + px; } } </script> </body> </html>

 

页面内容如何随窗口(宽度)的改变而改变大小?

原文:https://www.cnblogs.com/FlyingLiao/p/11577926.html

(1)
(1)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!