How to apply tr border to tables in Internet Explorer 6
Updated: 2006-05-11
I am sure many of you may have come across this during your design phase; IE6 does not acknowledge borders for the tr element. What is the work around you ask?
Since fighting with Internet Explorer to get certain styling working is a futile war, in some cases we have to pull a few tricks. The key in this trick is to give the illusion that the td element is continuous in a given tr. It is that simple. Assign the collapse value for the border-collapse property to get rid of any of the spacing between td's on a given table. Then add your preferred border style for all of the td's within that tr. The following code illustrates this idea (specific styling for a tr can be made by adding a class for that row).
table { border-collapse:collapse; }
td { border-bottom:1px solid #0f0; }
| Row1, Col1 | Row1, Col2 | Row1, Col3 |
| Row2, Col1 | Row2, Col2 | Row2, Col3 |
| Row3, Col1 | Row3, Col2 | Row3, Col3 |
In this case, border-collapse must be collapsed to get the right effect in Internet Explorer. This idea seems quite simple, yet easily overlooked or not worthy of attention because well... its for Internet Explorer. Why IE simple does not style tr is in the same set of mind-boggling questions that has been inquired about IE.
For further details, please see W3C's table border models in CSS.
- Tags
Interactions
43 interactions
on
Thank you very much :]
on
I've been struggling with this. Thanks for the confirmation that IE just doesn't honor border properties on tr's and for the suggested workaround.
on
It is possible to get IE to apply the row border to all member td's using the following code: tr td { border:1px solid green; }
on
Thanks for the info. I've had this trouble for quite a while now, and couldn't figure out if it was IE's fault or just me, and found no workaround. Your solution works like a charm.
on
Nice idea, but when you want to give a tr a left, right and top border you will need at least 3 different classes. Not very efficient. Any idea how to solve that?
on
I'm very sorry, but these are cell borders. To let it look like a real row border (so no border between col1 and col2), you have to make a whole mass of css...
on
No you don't...
table tr td { border-bottom:1px solid green }
or...
table tr td { border-top:1px solid green }
Mix and match according to taste!
on
@Johan you are correct, I noticed that as well and left the 'updated' note to be revisited.
@rob: thank you for initiating this.
(Sorry for the slow response)
on
Thanks a lot . This solved my problem of providing border to only td.
on
Hi, the above method helps to get border for all the trs in the table. What should be done to get border for a particular tr alone
Thanks Sumesh
on
Thanks for the tip, but I can't get it to work. Does this depend on a particular doctype declaration?
on
U can give "display:block" property to show borders on tr.
on
Hi Sumesh, to get a border for just one row, do this:
table tr.special td { border-bottom:1px solid green }
and then any tr element that you specify with a class of "special" will have a line under it.
on
Thank You Indeed , i used this trick in my website.
on
Wow such a basic thing but yes works like a charm. IE - you rogue! Thanks for the clear presentation of good info.
on
@AJ: This code don't display border on Internet Explorer :) only Firefox.
table tr.special td { border-bottom:1px solid green }
on
I get a little more frustrated each time I use an MS product. From SQL to Vista to IE, they're just poor products.
<tr ...
works great in Konquerer. It works as one would expect it to work. MS has this insatiable urge to force people in the direction MS thinks is best. It would be analogous to driving a highly automated car that forced you to take the shortest route when today, you wanna take the scenic route.
I steer as many people as I can away from MS products and only use them when the job absolutely requires it.
on
Thank you very much, this was very helpful.
on
@Splendor, johan, rob
To clarify rob's fix, you can do the border-bottom (or top) on the tds, and then the left/right/top (or bottom) on the table itself.
on
I think IE does display the borders, but it is invinsible. I set the border color to black or green or whatever and it shows right.
<TABLE BORDER=1 BORDERCOLOR=BLACK>
on
If in the case you need
table {border-collapse: separate}
You can add a empty <tr>, like this:
tr.line {height:1px;background:black}
And in most case you need "colspan" to finish it.
<tr><td></td></tr>
on
Thank you so much.. saved me much frustration.
on
Thank you so much.
on
Excellent article. I needed to put a right border on all trs except for the first one. Your solution worked. Thanks
on
Stupid IE! I think W3C need to legislate a law against Microsoft Internet Explorer standards.
It is very annoying for web developers to support websites in IE standards.
Microsoft, It's so hard to follow the W3C standards??? Why you always need to be abnormal???
on
table { border-collapse:collapse; } didn't work for me...
but -
table tr.someclass td {borderyoulike} as AJ said works on IE6 and IE7 in my case. try it out.
@DNA - i totally agree
on
In ie, thead,tr 's border or background-image has this problem.
How do you realise this: tr.highlight{border:1px solid red;}
<tr>???</tr> <tr>...</tr> <tr>???</tr> <tr>...</tr> <tr>???</tr> <tr>...</tr>
it's easy in Firefox!
on
Thanks for saving my day!!
on
Thank you very much. till now we are using bg for getting border but now due to tour code it worked.
on
2 xcf:
I fond interesting solution for Rows image background, the rows highlighting on mouse over, without JS.
tr { background-image: IMG_SRC;}
tr:hover { background-image: IMG_SRC2;}
here is a full article: http://www.sopov.com/joomla-wordpress-tips-and-tricks/70-how-highlight-table-row-background.html
Works in all browsers. For IE6/7/8 FIX: add to tr{ position: relative; } and td{ background-image: none } and for Safari i use negative background position for each TD.
on
Exact solution of what I've been looking for. THank you so much for sharing!!
on
wow thanks it works! I'm about to remake my code for IE though...
on
simple solution to a frustrating problem. thanks :)
on
Thanks for the tip!
on
Thanks a lot man. It really helped me a lot. An awesome solution yaar.
on
Thank you very much for the tip !
on
This will not work if the cell is empty. I am having issues.
Thanks for the write up!
on
Out of all the solutions out there on google, this is the only one that worked for me. Thanks a ton man !
on
Interestingly, row borders seem to work in IE8 when running code in the Visual Studio 10 IDE, but not when deployed to IIS6/7. Come on Microsoft - sort it out!
on
Thanks for this! I could never figure out why borders looked different in IE than in every other browser. Wish MS would get their act together...
on
Nice job! It solved my problem with IE7. I was applying border-bottom to "tr" tag but for IE7 must be on "td" tag.
on
Thankx very much for this fix. Helped me out with my <tr> border issue.
on
Compatible with IE8 too??