View Full Version : How do I center my applet?

11-09-2012, 02:22 AM
Hey guys I am working on a webpage and would like my applet to be centered on the page but am not 100% sure how to do that. Here is the source.

<title> My Applet </title>
<body bgcolor="00000" text="00ff00">
<h1 align="center">My Applet</h1>
<applet code="applet.class" width=500 height=300>
It seems your browser does not support java, or java is not enabled. Sorry!

Any help I can get would be much appreciated

11-09-2012, 02:47 AM
Hello FlexBuffChest92,
To center an element you need three things:

a valid DocType
an element with a width
that elements right/left margins set to auto

11-09-2012, 02:55 AM
Would I use <div> then?

11-09-2012, 03:06 AM
"My Applet" is in heading tags that can be centered with those same rules.

See a very simple example here -
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
html, body {
margin: 0;
background: #fc6;
#container {
width: 800px;
margin: 30px auto;
padding: 200px 0 300px;
background: #fff;
box-shadow: 0 0 20px #8493A6;
overflow: auto;
h1 {
width: 200px;
margin: 0 auto;
background: #333;
<div id="container">
<h1>My Applet</h1>
<!--end container--></div>