可以将 100% 高度转换为像素

Can covert 100% height to pixels

在 HTML 中使用高度为 100% 的 div。我需要像素而不是百分比。有谁知道如何在不给出任何特定像素值的情况下实现 100% 到像素?

你必须使用 javascript。

<html>
<head>
<script>
window.onload= total_y;
   function total_y(){
       var x = screen.height + "px";
    document.getElementById("bo").style.height= x ;    
    document.getElementById("bo").style.background= "red" ;
    }
</script>
    </head>
    <body id="bo">
    </body>
    </html>

同样的答案,你必须使用JS。也许你可以使用这个:

<html>
    <head>
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
        <style>
            html, body {
                width: 100%; height: 100%;
                padding: 0px; margin: 0px;
            }
            #foo{
                background-color: #ffff00;
            }
        </style>

        <script>
            $(document).ready(function () {
                var tHeight = $(window.top).height();
                alert("Visible screen height is " + tHeight + "px");
                $("#foo").height(tHeight);

            });
        </script>
    </head>

    <body>
        <div id="foo">
            THERE YOU GO!
        </div>
    </body>
</html>

希望对您有所帮助