Page 1 of 1

How do I add a right border, every three <td>?

Posted: Tue Aug 05, 2014 11:20 am
by simonmlewis
I'm doing this in <td> cells so it's just two columns on a page.

But I need to add a right border down the centre. So it needs to be on the first cell, but then on, every 2 cells.
So far all I am getting is the first one with a border, then the third one (directly below), and then the one below that doesn't get a border, but it gets it on the 6th cell (so a border on the right edge of the browser).

I need it straight down the middle.

Code: Select all

 if($cat % $n == 0 && $cat != 0) // If $c is divisible by $n...
  {
    // New table row
    echo '</tr><tr>';
  }
  
  
			echo "<td width='50%'><div class='";

			if ($row->catid == $catid) { echo " mainmenusubon";}
			else { echo "mainmenusub";}
			echo "'  ";
			$x++;
			if(fmod($x,3) == 0 || $x == 1)
  {
    // New table row
    echo "style='border-right: 1px solid #ffff00;'";
  }
  
			
			echo ">
        <a href='/categ/$row->catid/$categreplace'>$row->category</a></div></td>";
        
        $cat++;

Re: How do I add a right border, every three <td>?

Posted: Tue Aug 05, 2014 12:36 pm
by requinix
This is a great application for CSS. Remove the DIV and use

Code: Select all

table.some-class-name-here tr td:first-child { border-right: 1px solid #ffff00; }

Re: How do I add a right border, every three <td>?

Posted: Tue Aug 05, 2014 2:06 pm
by simonmlewis
Why does that now add some kind of padding or margin around the table tho?
I've tried:
table.mainmenu tr td:first-child { border-right: 1px solid #545454; }
table.mainmenu {margin: 0px;}

But the margin remains.

Re: How do I add a right border, every three <td>?

Posted: Tue Aug 05, 2014 2:15 pm
by Celauran
We don't really have enough information to answer that. Is there somewhere we can see what you mean, along with the relevant CSS? Surely more than just those two lines are affecting the display of the table.

Re: How do I add a right border, every three <td>?

Posted: Tue Aug 05, 2014 2:16 pm
by simonmlewis
Actually no.
The table has the cellpadding and cellspacing both set to zero.
Without this code given above, the spacing is fine. Adding it, and there is a gap all the way around the table.

Re: How do I add a right border, every three <td>?

Posted: Tue Aug 05, 2014 2:19 pm
by Celauran
Maybe this? Without seeing what you're talking about, I'm literally guessing.

Code: Select all

table.mainmenu {
    border-collapse: collapse;
}

Re: How do I add a right border, every three <td>?

Posted: Thu Aug 07, 2014 8:45 am
by simonmlewis
Sorted it, my bad. works brilliantly. :)