Search code examples
htmlcssappletcentermargin

Cannot center Java Applet in HTML file


I need to center my applet horizontally AND vertically but I can only center it horizontally. Can any one help with this simple CSS problem? I have tried using "display: inline-block;" and "display: block;" but both of this has no effect. Here is my code:

<!DOCTYPE html>
<html>
    <head>
        <title>testing..</title>    
        <style type="text/css">
            html, body {
                margin: 0;
            }
            #container {
                width: 640px;
                height: 610px;              
                margin: auto;
            }
        </style>
    </head>
    <body>
        <div id="container">
            <applet code="TetrisApplet.class" width="640" height="610"/>
        </div>
    </body>
</html>

Solution

  • You can use same width of div and applet or put applet into new div width display:inline-block;