Jump to content
  • 0

Выравнивание div внутри td


jools
 Share

Question

Здравствуйте!

Проблема в том, что не смотря на text-align: center у TD, div, который внутри, не хочет выравниваться по центру. В чем проблема?

Вот кодик:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Man</title>
<style>
.fighter {width: 200px; border-collapse: collapse;}
.fighter td {border: 1px solid #000; vertical-align: top;}
.head {text-align: center;}
.head div {width: 50px; height: 50px; border: 1px solid #777; text-align: center;}

.left_hand {text-align: right;}
.left_hand div {width: 20px; height: 90px; border: 1px solid #777; text-align: center;}

.right_hand {text-align: left;}
.right_hand div {width: 20px; height: 90px; border: 1px solid #777; text-align: center;}

.left_body {text-align: right;}
.left_body div {width: 30px; height: 110px; border: 1px solid #777; text-align: center;}

.right_body {text-align: left;}
.right_body div {width: 30px; height: 110px; border: 1px solid #777; text-align: center;}

.left_leg {text-align: center;}
.left_leg div {width: 20px; height: 110px; border: 1px solid #777; text-align: center;}

.right_leg {text-align: center;}
.right_leg div {width: 20px; height: 110px; border: 1px solid #777; text-align: center;}
</style>
</head>
<body>
<table cellspacing="0" cellpadding="0" border="0" class="fighter">
<tr>
<td> </td>
<td class="head" colspan="2"><div></div></td>
<td> </td>
</tr>
<tr>
<td class="left_hand"><div></div></td>
<td class="left_body"><div></div></td>
<td class="right_body"><div></div></td>
<td class="right_hand"><div></div></td>
</tr>
<tr>
<td> </td>
<td class="left_leg"><div></div></td>
<td class="right_leg"><div></div></td>
<td> </td>
</tr>
</table>
</body>
</html>

Edited by jools
Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

text-align: center работает только для инлайновых элементов, если div вы замените на span - то всё будет великолепно.

Если укажете у td ширину, не в процентах, а в пикселях, то div можно будет выровнять через margin:0 auto;

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. See more about our Guidelines and Privacy Policy