0

I have a following code:

<html>
<head>
<style>
    table {
        border: solid red 2px;
    }
    tr {
        border: solid red 2px;
    }
    td {
        border: inherit;
    }
</style>
</head>
<body>
    <table>
    <tr>
        <td> 1 </td> <td> 2 </td>
    </tr>
    <tr>
        <td> 1 </td> <td> 2 </td>
    </tr>
    </table>
</body>
</html>

It works correctly. A property border of "tr" inherit by child "td".

But this code work differently, in spite of fact, that logical of work is the same:

<html>
<head>
<style>
    table {
        border: solid red 2px;
    }
    tr {
        border: inherit;
    }
    td {
        border: inherit;
    }
</style>
</head>
<body>
    <table>
    <tr>
        <td> 1 </td> <td> 2 </td>
    </tr>
    <tr>
        <td> 1 </td> <td> 2 </td>
    </tr>
    </table>
</body>
</html>

There is property border of "tr" don't inherit by child "td". Why?

2
  • tr is td's child? Commented Oct 13, 2014 at 5:33
  • Vise versa. If I write a question incorrectly edit him please. Commented Oct 13, 2014 at 5:35

1 Answer 1

5

In the final html that is rendered, tr is not child of table but tbody.

Hierarchy is: table -> tbody -> tr

Default border of tbody is not inherit but `medium , therefore, tr doesn't inherit.

Try this:

tbody, tr {
    border: inherit;
}
Sign up to request clarification or add additional context in comments.

2 Comments

It is nice explanation. I don't know about a existing of a implicit tag tbody... damn.
it's still valid not to explicitly put tbody. See w3.org/TR/html-markup/tbody.html A tbody element's start tag may be omitted if the first thing inside the tbody element is a tr element

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.