HTML: Can someone please tell me why my <tr> borders won't show?

I'm trying to put a border-top on the <tr> elements of my <table>, but it won't show. Can someone please tell me why?

Here is my code snippet:

<!DOCTYPE html>
<html>
<head>
<title></title>
<style>
    table {
        width: 300px;
        border: 1px solid lightgray;
    }
    tr {
        border-top: 1px solid red; /* WHY ISN'T THIS BORDER SHOWING? */
    }
</style>
</head>
<body>
    <table>
        <tr><td>Row 1</td></tr>
        <tr><td>Row 2</td></tr>
        <tr><td>Row 3</td></tr>
    </table>
</body>
</html>

Open in new window


Thanks.
elepilAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Om PrakashCommented:
Try this:

<!DOCTYPE html>
<html>
<head>
<title></title>
<style >
    table {
        width: 300px;
        border: 1px solid lightgray;
    }
    td {
        border-top: 1px solid red;
    }
</style>
</head>
<body>
    <table>
        <tr><td>Row 1</td></tr>
        <tr><td>Row 2</td></tr>
        <tr><td>Row 3</td></tr>
    </table>
</body>
</html>

Open in new window

0
elepilAuthor Commented:
Om Prakash, thanks for responding.

I knew I could use the <td>, but it has to be on the <tr>. This page I'm making is an appointments screen. Appointments will be in the <td> elements, and doing it your way would mean there would be no horizontal lines if the page has no appointments.
0
Dave BaldwinFixer of ProblemsCommented:
It can't be on the <tr> because <tr> are not visible elements.  They are grouping elements that are used to define a row made up of <td>s.  I suggest you use &nbsp; to fill blank rows.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Julian HansenCommented:
Add this to your table style

table {
    width: 300px;
    border: 1px solid lightgray;
    border-collapse: collapse; /* ADD THIS */
}

Open in new window


Refer to the specification here - specifically section 17.6.2 The collapsing border model which states
In the collapsing border model, it is possible to specify borders that surround all or part of a cell, row, row group, column, and column group. Borders for HTML's "rules" attribute can be specified this way
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
elepilAuthor Commented:
Thanks, JulianH, for the right-on-the-mark solution!

Thanks to the rest, too, for responding.
0
Julian HansenCommented:
You are welcome.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.