...

View Full Version : How do I center my applet?



FlexBuffChest92
11-09-2012, 01: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.

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

Any help I can get would be much appreciated

Excavator
11-09-2012, 01: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

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

Excavator
11-09-2012, 02: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">
<head>
<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;
}
</style>
</head>
<body>
<div id="container">
<h1>My Applet</h1>
<!--end container--></div>
</body>
</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum