...

View Full Version : How do you style your PHp with CSS??



staycee
06-21-2006, 03:48 AM
i hope some one can help me...

im a bit lost on how the hell you add css styling into the PHP page?? Ive got an external link to the css..but im not quite sure exactly WERE in the code i place the CSS??

Like how would i style this simple table that i have on my page??


<table width="400" border="1" cellspacing="0" cellpadding="5">
<?php do { ?>
<tr>
<td rowspan="2"><img src="<?php echo $row_rs_index['image']; ?>" /></td>
<td><?php echo $row_rs_index['title']; ?></td>
<td><?php echo $row_rs_index['author']; ?></td>
</tr>
<tr>
<td colspan="2"><?php echo $row_rs_index['review']; ?></td>
</tr>
<?php } while ($row_rs_index = mysql_fetch_assoc($rs_index)); ?>
</table>


i know its probably realy simple!! but im stuck..and all the php code is confusing me (lol)


thanx guys!! :thumbsup:

xconspirisist
06-21-2006, 05:08 AM
You are using 3 different languages.

That code you pasted is HTML and CSS. I suggest in the future you use CODE tags when pasting code.

Add this line to the top of your page header.



<!-- doctype !-->

<head>
<title><!-- title !--></title>
<link rel = "stylesheet" href = "style.css" type = "text/css" />
</head>

<body>
--- rest of your page ---


You will then need to learn CSS, and create a new file called "style.css".

Something to get you started:



table {
background-color: red;
}

tr {
background-color: blue;
}

td {
background-color: green;
color: white;
}

staycee
06-21-2006, 06:09 AM
i dont understand?? maybe i didint explain myself very well...

i alredy KNOW CSS...and alredy have a linked style sheet...the bit im unsure about is were abouts in the HTML do i put classes and ids and divs for styling?? I know in a normal page i would for example just give the <td> a id...and style that specific <td> BUT with all the extra PHP code in there i am unsure were to place them?

does that make sense??

xconspirisist
06-21-2006, 06:19 AM
Is this what you mean?



<td class = "one"><?php echo $row_rs_index['title']; ?></td>
<td class = "two"><?php echo $row_rs_index['author']; ?></td>


Reference them like this:



td.one {
background-color:red;
}

td.two {
background-color: blue;
}

staycee
06-21-2006, 06:23 AM
yeah!! the only reason i ask were to place them is because some one else told me to move the all php and place the styling inside divs AROUND the php. :confused: :confused: .......But i shall try your way and see......

i guarantee ill be back with more questions hehe

felgall
06-21-2006, 11:04 PM
The CSS styles the HTML after it has been generated from the PHP and sent to the browser so there is no PHP in the page once the CSS is used.

Raraken
06-22-2006, 02:25 AM
You want to put style information in the <head> area of your page, that would be above the code you posted.

When working with PHP like that, treat it like any normal HTML page, with all the HTML tiddlybits; PHP never actually shows up on the pages users see, all the users get is the HTML.


Insert CSS Here.
<table width="400" border="1" cellspacing="0" cellpadding="5">
<?php do { ?>
<tr>
<td rowspan="2"><img src="<?php echo $row_rs_index['image']; ?>" /></td>
<td><?php echo $row_rs_index['title']; ?></td>
<td><?php echo $row_rs_index['author']; ?></td>
</tr>
<tr>
<td colspan="2"><?php echo $row_rs_index['review']; ?></td>
</tr>
<?php } while ($row_rs_index = mysql_fetch_assoc($rs_index)); ?>
</table>

PHP tags "dissappear" in the final page, and when you were told to put CSS "around" the PHP tags, he meant just not to put them inside the PHP code itself.

Good<?php Not so Good ?>Good



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum