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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

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

Post 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++;
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

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

Post 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; }
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

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

Post 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.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

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

Post 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.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

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

Post 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.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

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

Post by Celauran »

Maybe this? Without seeing what you're talking about, I'm literally guessing.

Code: Select all

table.mainmenu {
    border-collapse: collapse;
}
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

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

Post by simonmlewis »

Sorted it, my bad. works brilliantly. :)
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
Post Reply