开发者

Align the table on the center of the page

开发者 https://www.devze.com 2023-01-30 15:50 出处:网络
I just want to put the table in the middle of the page. Any help would be great. <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"

I just want to put the table in the middle of the page. Any help would be great.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
        "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>Randy's first html web page !</title>
<style type="text/css">
body
{background-image:url('Koala.gif');} 
h1
{
text-align:center;
}
h2
{
text-align:center;
}
p
{
text-align:center;
font-size:200%;
color:#00fff0;
}
div
{
background-color:#efffff;
}
</style>
</head>
<h1> Hello Professor</h1>
<h2> By: Randy White</h2>
<P> I haven't done anything like this before.</P> 
<P>Seems to be ok</P>
<P><img src="Hydrangeas.jpg" width="150" height="100" alt="Hydrangeas.jpg"></P> 
<table border="1">
<tr>
<th>Month</th>
<th>Day</th>
<th>Year</th>
</tr>
<tr>
<td>December</td>
<td>1</td>
<td>2010</td>
&开发者_如何学Golt;/tr>
</table>
<a href="http://www.google.com">Visit Google!</a>
</body>
</html>


Try:

table {
    width: 50%;
    margin-left: auto;
    margin-right: auto;
}

or:

table {
    width: 200px;
    margin-left: auto;
    margin-right: auto;
}

BTW, this sets this for all tables. You might want to have the properties on a more specific selector (like table.someclass).


old style is align="center":

<table width="400" border="0" cellspacing="0" cellpadding="0" align="center">


To horizontally align table in the middle of the page, and also make table width fit itself automatically, try below:

table {
    width: auto;
    margin-left: auto;
    margin-right: auto;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消