代码之家  ›  专栏  ›  技术社区  ›  Stefan Kendall

覆盖整个屏幕的画布元素?

  •  0
  • Stefan Kendall  · 技术社区  · 14 年前

    我想用 <canvas> 在iPhone Safari中,如果我将元素放在主体中,元素的左侧和顶部会有未使用的像素。我试图说明 margin:0;padding:0 没有CSS。

    这是怎么回事?

    <html>
    <head>
            $(document).ready(function()
            {
                $('#screen').attr("height", $(window).height() );
                $('#screen').attr("width", $(window).width() );
    
                //prevent scrolling
                $(document).bind('touchstart touchmove', function(e)
                {
                    e.preventDefault();
                });
            });
        </script>
    </head>
    <body>
    <canvas id = "screen">
    </canvas>
    </body>
    </html>
    
    2 回复  |  直到 12 年前
        1
  •  1
  •   Stefan Kendall    14 年前

    margin , padding border 没有效果。

    使用 position:absolute; top:0;left:0

        2
  •  -1
  •   antimatter15    14 年前

    添加 <style>* {margin:0;padding:0;border:0;position:absolute;width:100%;height:100%}</style>