max-width ignored on td element

SO #12978619 http://stackoverflow.com/questions/12978619/html-table-max-width-ignored-on-child-element/12979049

by Hashem Qolami

HTML

<div>
<input type="text" size="40" />
<table>
<tr>
    <td>
        <input type="text" size="40" />
    </td>
</tr>
</table>
<table>
<tr>
    <td>
        <span>Hello!</span>
    </td>
</tr>
</table>
</div>

CSS

div {
    padding: 2em;
    background: #aff;
}

table {
    margin: 6px 0;
    width: 100%;
    background: #afa;
    table-layout: fixed;
}

td {
    padding: 6px 15px;
}

input, td span {
    font-family: serif;
    font-size: 1em;
    display: block;
    border: 1px solid #999;
    background: #fff;
    border-radius: 5px;
    padding: 9px;
    margin: 0 -9px;
    max-width: 100%;
}

td span {
    width: 40ex;
}