Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set border to table tr, works in everything except IE 6 & 7

Tags:

I set the border for the table event_calendar tr to be red, it works in everything except IE 6 & 7. What is wrong with my CSS?

table#event_calendar tr {     border:1px solid red; }  <div class="content-body"> <table id="event_calendar">     <tr class="calendarHeader">         <th><div class="calendarMonthLinks"><a href="http://webdev.herkimer.edu/calendar/2009/03/">&lt;&lt;</a></div></th>         <th colspan="5"><h1>April 2009</h1></th>         <th><div class="calendarMonthLinks"><a class="calendarMonthLinks" href="http://webdev.herkimer.edu/calendar/2009/05/">&gt;&gt;</a></div></th>     </tr>     <tr>         <td class="calendarDayHeading">Sunday</td>         <td class="calendarDayHeading">Monday</td>         <td class="calendarDayHeading">Tuesday</td>         <td class="calendarDayHeading">Wednesday</td>         <td class="calendarDayHeading">Thursday</td>         <td class="calendarDayHeading">Friday</td>         <td class="calendarDayHeading">Saturday</td>     </tr> </table> </div> 
like image 409
Brad Avatar asked Feb 24 '09 20:02

Brad


People also ask

How do you set a border on TR?

Not directly: adding a border to a tr isn't allowed. But you can target the first and last cell, give those a left/right border respectively. Then on each cell put a top border and a bottom border on each td element.

Can TR element have border?

Borders can be added to rows of table by adding border to <td> and <th> elements [This is basically a CSS trick to achieve (hack!) that as borders cannot be added to <tr> and <tbody> elements of table]. Add following styles to your CSS to get borders around rows or headers or table cells.

Why is my border not showing up CSS?

CSS Border Not Showing If you've set the shorthand border property in CSS and the border is not showing, the most likely issue is that you did not define the border style. While the border-width and border-color property values can be omitted, the border-style property must be defined. Otherwise, it will not render.

How do you display table borders?

To create table border in HTML, the border attribute was used. But the introduction of HTML5, deprecated the border tag. Create table border using the CSS property border. Set table border as well as border for <th> and <td>.


2 Answers

IE does not honor the border property for <tr> tags. However, there are workarounds by putting a top and bottom border around each cell, and using "border-collapse: collapse;" so there's no space between cells. I will refer to this resource here on the exact method, but it will essentially look like this for you (I haven't tested it myself, so I'm not sure if this is exactly right, but I think you can riff on it.)

table#event_calendar {     border-collapse: collapse;     border-right: 1px solid red;     border-left: 1px solid red; }  table#event_calendar td, table#event_calendar th {     border-top: 1px solid red;     border-bottom: 1px solid red; } 
like image 197
Dan Lew Avatar answered Dec 23 '22 12:12

Dan Lew


Your CSS is sensible enough, but IE just doesn't do borders on tr elements. If you use this style you should get the intended result though:

table#event_calendar {     border-top:1px solid red;     border-right:1px solid red;     border-left:1px solid red;     border-collapse:collapse; }  table#event_calendar td, table#event_calendar th {     border-bottom:1px solid red;  } 
like image 30
Thomas Petersen Avatar answered Dec 23 '22 12:12

Thomas Petersen