2010-12-14 6 views
8

Je veux juste placer la table au milieu de la page. Toute aide est la bienvenue.Aligner le tableau au centre de la page

<!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> 
</tr> 
</table> 
<a href="http://www.google.com">Visit Google!</a> 
</body> 
</html> 

Répondre

24

Essayez:

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

ou:

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

BTW, cela définit ce pour toutes les tables. Vous voudrez peut-être avoir les propriétés sur un sélecteur plus spécifique (comme table.someclass).

+0

Cette ne semble pas fonctionner. Peut-être que je le mets au mauvais endroit. Pouvez-vous me dire où cela irait? – user770022

+0

Petite erreur de ma part, je la voulais trop courte;) Essayez maintenant, ça marche. – Kos

+0

qui l'a eu grâce – user770022

2

style ancien est align = "center":

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

Pour horizontalement aligner la table au milieu de la page, et aussi s'adapter à rendre la largeur de la table automatiquement, essayez ci-dessous:

table { 
    width: auto; 
    margin-left: auto; 
    margin-right: auto; 
} 
Questions connexes