Results 1 to 5 of 5

Thread: PHP and CSS? (Beginner)

  1. #1
    Join Date
    Jan 2008
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question PHP and CSS? (Beginner)

    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.
    Last edited by rpflorence; 01-20-2008 at 03:09 AM. Reason: formatting

  2. #2
    Join Date
    Mar 2007
    Location
    Tarboro, NC
    Posts
    290
    Thanks
    8
    Thanked 2 Times in 2 Posts

    Default

    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:

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

  3. #3
    Join Date
    Jan 2008
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    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?

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    .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).
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    You can even make it a .html or .htm file and use CSS to force htm and html files to parse php. pretty neat:

    Code:
    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.
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •