Log in

View Full Version : PHP and CSS? (Beginner)



rpflorence
01-20-2008, 03:08 AM
I'm a web designer and I've been cranking out some PHP for the first time this week.

Basic question, I believe.

I've noticed in my .php files I have to define my styles inline, which makes want to cry--a lot. If I drop the CSS link in the <head> of the .php file it doesn't grab it and I'm left with no style.

How can I reference a stylesheet in a .php file?

Or should I be referencing my PHP code in my HTML? I don't know enough right now to grab the php variables and print that information in an html file. Maybe I'm just getting ahead of myself.

TimFA
01-20-2008, 03:20 AM
Either way you can't "reference" your PHP files in such a way as to prevent this, since 1) it still needs the extension .php 2) it uses a PHP function, include() to bring in the PHP. Try using the absolute path, i.e. http://www.yoursite.com/css/layout.css I have plenty of PHP pages using CSS.

Btw heres how to reference an external PHP file:



<?php
include("path_to_file.php");
?>

rpflorence
01-20-2008, 03:48 AM
Hey, it works, thanks. (But that is annoying considering I move my files around from machine to machine so often.)

So ... even though it's .php I still define it with the appropriate <!DOCTYPE ...> right?

djr33
01-20-2008, 07:52 PM
.php is just a marker that makes the page be parsed as a PHP file. That's ALL. Use html as you would in any other file, including doctype and css (embedded, external, whatever).

BLiZZaRD
01-21-2008, 04:28 AM
You can even make it a .html or .htm file and use CSS to force htm and html files to parse php. pretty neat:



AddType application/x-httpd-php .html .htm
AddHandler application/x-httpd-php .html .php .htm


those two lines in a .htaccess file and you can use the .htm and .html extension.