<html> <body> <div class="example"> </div> </body> <html> html{ height:100%;//让html的高度等于屏幕 } body{ height:100%; margin:0; } .example{ width: 100%; height:100%; background:rgb(55, 137, 243); } |
<html> <body> <div class="example"> </div> </body> <html> .example{ position: absolute; top:0; left:0; bottom:0; right:0; background:rgb(55, 137, 243); } |
<html> <body> <div class="example2"> <span class="example"></span> </div> </body> <html> .example2{ position: relative; width:100%; height:100px; } .example{ position: absolute; top:0; left:0; bottom:0; right:0; background:rgb(55, 137, 243); } |
<html> <body> <div class="example"> </div> </body> <html> .example{ position: fixed; top:0; left:0; bottom:0; right:0; background:rgb(55, 137, 243); } |
<html> <body> <div class="example"> </div> </body> <html> html,body{ width:100%; height:100%; } body{ display: flex; } .example{ background:#fc1; flex:1 1 a |
<html> <body> <div class="example"> </div> </body> <html> <script> let example = document.getElementById('example') let height = document.documentElement.clientHeight example.style.height = `${height}px` </script> |