Php tables with css

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
MHardeman25
Forum Commoner
Posts: 42
Joined: Mon Jul 12, 2010 10:34 am

Php tables with css

Post by MHardeman25 »

Damn, I really hate to be a burden. This is the second time in about 4 hours I've posted with something that is probably a simple error.
Anywho, I'm trying to apply css to a table that I'm printing out with php. The code looks kind of like this.

Code: Select all

<div id='info'>
<link rel='stylesheet' href='content-layout.css'>
	<table class='infoTable'>
	<?php
		foreach($userInfo as $field => $value){
			echo '<tr>';
			echo "<td class='elements'>".$field."</td><td>".$value."</td>";
			echo '</tr>';
		}
	?>
	</table>
</div>
the css is in a seperate file, the one I referenced with the link.
it looks like this

Code: Select all

body
{
	margin: 0;
	color: #666666;
	background-color: #000000;
	font-family: serif, verdana;
}

#info.infoTable
{	
	border: 1px solid #FFFFFF;
	background-color: #666666;
	padding: 5%;
}
basically, the css doesn't work on the table, I've tried everything. Changing the classes to id's and back
applying the css to different parts. Changing where the table tag is in the html/php. I got nothing.
jraede
Forum Contributor
Posts: 254
Joined: Tue Feb 16, 2010 5:39 pm

Re: Php tables with css

Post by jraede »

Your CSS isn't doing what you want it to do - I'm not sure if "#info.infoTable" is even valid syntax, but if it is, then it's selecting anything with id="info" and class="infoTable". Put a space in between to select any element with class "infoTable" within an element with id "info".
MHardeman25
Forum Commoner
Posts: 42
Joined: Mon Jul 12, 2010 10:34 am

Re: Php tables with css

Post by MHardeman25 »

sorry, it should be just a .infoTable, but that doesn't work either.
jraede
Forum Contributor
Posts: 254
Joined: Tue Feb 16, 2010 5:39 pm

Re: Php tables with css

Post by jraede »

What does your CSS file look like now?
MHardeman25
Forum Commoner
Posts: 42
Joined: Mon Jul 12, 2010 10:34 am

Re: Php tables with css

Post by MHardeman25 »

Code: Select all

body
{
	margin: 0;
	color: #666666;
	background-color: #000000;
	font-family: serif, verdana;
}

.infoTable
{	
	border: 1px solid #FFFFFF;
	background-color: #666666;
	padding: 5%;
}
MHardeman25
Forum Commoner
Posts: 42
Joined: Mon Jul 12, 2010 10:34 am

Re: Php tables with css

Post by MHardeman25 »

even if I do this, I get nothing. The css is as simple as it gets, I don't see the problem.

Code: Select all

body
{
	margin: 0;
	color: #666666;
	background-color: #000000;
	font-family: serif, verdana;
}

#info
{	
	border: 1px solid #FFFFFF;
	background-color: #666666;
	padding: 5%;
}

.infoTable
{	
	border: 1px solid #FFFFFF;
	background-color: #666666;
	padding: 5%;
}

.elements
{	
	border: 1px solid #FFFFFF;
	background-color: #666666;
	padding: 5%;
}
all i'm really trying to do is put boarders and colors so i can see what i'm doing.
jraede
Forum Contributor
Posts: 254
Joined: Tue Feb 16, 2010 5:39 pm

Re: Php tables with css

Post by jraede »

From my experience it's easier to style TR than TD (in fact, I've noticed that TD doesn't work on many occasions). But as far as the table as a whole, it's hard for me to help you if I can't see it. Is the white border showing up at all?
MHardeman25
Forum Commoner
Posts: 42
Joined: Mon Jul 12, 2010 10:34 am

Re: Php tables with css

Post by MHardeman25 »

Hold on, for some crazy reason, it just randomly decided to work.
MHardeman25
Forum Commoner
Posts: 42
Joined: Mon Jul 12, 2010 10:34 am

Re: Php tables with css

Post by MHardeman25 »

I haven't changed anything. I just refreshed the page like 10 times and it finally worked.
jraede
Forum Contributor
Posts: 254
Joined: Tue Feb 16, 2010 5:39 pm

Re: Php tables with css

Post by jraede »

Your browser probably cached the old CSS file. Glad it's working now.
Post Reply