0

Common

table tr td
{
    vertical-align:middle;
}

Custom

table.custom tr td
{
    vertical-align:top;
}

When I use like this:

<table class="custom">
    <tr>
        <td>
            <table>
                <tr>
                    <td>this text align top, but I want to align middle
                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>

sub table behave like its parent. How can ignore parent element style?

3 Answers 3

1

One thing that you can do is adding the child selectors like so:

table.custom > tr > td { }

Then only the immediate children will match the style

Sign up to request clarification or add additional context in comments.

Comments

1

You can use the > indicator to only target direct child elements

table.custom > tr > td
{
    vertical-align:top;
}

However it should be noted that using a table within a table is generally not a good idea. Note 2: this will not work in IE6.

Comments

1

table.custom tr td will select children at any level. The following DOM chains will all match

table.custom->tr->td
table.custom->tr->foo->td
table.custom->foo->tr->bar->td

Take a look at the CSS child selector >

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.