+1  A: 

untested: take out 'margin-left' and use 'padding-left' instead.

or

You could indent your cells value without using a nested table, by adding the padding-left to your parent tables 'td'.

Jobo
Yes, this solves the problem. But why?
Alessandro Vernet
The reason is because your child table has its width set to 100% which means it will always completely fill the space in which its in. Further to that, the margin-left pushes it way over that 100% threshold and outside of it its space that its filled up.
Jobo
A: 

This is because you're giving the table width 100%. It adds the margin onto this, such that the element has >100% width. If you want to get around this, add a div or something above the nested table with a margin: 3em and you can leave the width of the table at 100%.

EDIT: In response to Jobo's comment to his answer, tds don't support margins; however, a padding-left: 3em should work instead.

jennyfofenny
A: 

This is not intended to be an attack, but rather an aid to help you be a better developer:

  1. There is NEVER a need to have sub tables.
  2. if you are going to use CSS then do it right, one or more external files.
  3. This will help you develop as a web developer - think about how you want to structure the page and then use the correct markup to produce that structure - once the markup is valid then you can worry about styling.
Jamie Lewis
-1 Sorry there are valid reasons to have nested tables, particularly with dynamically generated content. Not common these days but never? No way.
cletus
Why would dynamically generated content effect the need for nested stables? Static and Dynamic content are all the same on the client side. If you are placing tables within tables then clearly the structure of you page is poor.
Jamie Lewis
tables are useful, shutup! -1
hasen j
+3  A: 

The inner table is being told to be as wide as its container (width: 100%), and then to move 3ems away from its left edge: (margin-left: 3em)

Switch the innermost TD to have padding-left which might help.

But the standard response here is: "oh god why are you doing nested tables you bad bad man!!11"

nickf
+1  A: 

This is happening because you are setting "margin-left: 3em", and it is pushing the sub-table outwards.

Marcel Tjandraatmadja
A: 

Try this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <body>

        <table border="1">
            <tr>
                <td style="padding-left: 3em;">
                    <table border="1" style="width: 100%;">
                        <tr>
                            <td>gaga</td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>

        <table border="1">
            <tr>
                <td>
                    <table border="1" style="margin-left: 3em; width: 100%">
                        <tr>
                            <td>gaga</td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>

    </body>
</html>

Changing margin-left from the TABLE element to padding-left on parent TD (like Jobo said)

Héctor Vergara R.
A: 

Just remove the "width" attribute of that table and you should see that it will stay within the cell, even with long text.

netrox