Hey,

I was wondering, how does one style fully style a page that is a result of PHP?
Let's assume that I have PHP that output a HTML form, I can add CSS to the element to style it, right?
But how do I style the body tag for example?

Thanks for the pointer.

Farcat

    Use an external css file called from the html - it's neither here nor there that the html is generated from the PHP
    Style the body in the css.

      OK, thanks @.
      I know how to do that on a HTML file but how to call an external css with PHP?
      Something like that?

      <?php include 'header.php'; ?>
      <style>
      <?php include 'style.css'; ?>
      </style>

        No you can't include a .css file like that
        Just do
        <link rel="stylesheet" href="style.css" type="text/css">
        within the relevant part of the html you are outputting - exactly as an ordinary html page

        If you want dynamic css that's a different matter ..

          cretaceous;11042661 wrote:

          No you can't include a .css file like that...

          Well, technically, you could, but I wouldn't. 🙂

          (You'd end up with the CSS info being embedded directly within your HTML output, which means the browser would not be able to cache it separately.)

            The bigger picture is that it doesn't matter if the HTML document is coming from a static .html file on your server or if it's some .php script. The end result is exactly the same as seen on the client side, thus the CSS/styling techniques are exactly the same as well.

              Thanks guys for your input.
              None the wiser here...:bemused:

              "Just do
              <link rel="stylesheet" href="style.css" type="text/css">
              within the relevant part of the html you are outputting - exactly as an ordinary html page"

              I am obviously missing something in the logic here. What I want to do is add a background to the html or body tag which is not generated by my PHP code.
              I can't target the relevant part of the HTML I am outputting.

              Where would I place :

              <link rel="stylesheet" href="style.css" type="text/css">

              within
              <?php My code ?>?

                Wherever is going to cause it to be output before the </head> tag (and, of course, after the <head> tag).

                Depending upon what the PHP code looks like, this might either be in an [man]echo[/man]/[man]print[/man] statement, or it could be outside of the <?php .. ?> tags altogether (after all, no PHP code is required to generate it - it's just a static string of data you're wanting to output).

                  I did try outside the <?php .. ?> tag but it does'nt seem to work.
                  Here is my code whuich uotput a form:

                  <?php
                  session_start();
                  include("pass.php");
                  if ($_POST["ac"]=="log") { 
                       if ($USERS[$_POST["username"]]==$_POST["password"]) {
                            $_SESSION["logged"]=$_POST["username"];
                            $temp = $_SESSION["logged"];
                  header("Location: ".$REDIRECT[$temp]);
                       } else {
                            echo 'Incorrect username/password. Please, try again.';
                       };
                  };
                  if (array_key_exists($_SESSION["logged"],$USERS)) {
                       echo "You are logged in";
                  } else { 
                       echo '<form action="login.php" method="post"><input type="hidden" name="ac" value="log"> ';
                       echo 'Username: <input type="text" name="username" />';
                       echo 'Password: <input type="password" name="password" />';
                       echo '<input type="submit" value="Login" />';
                       echo '</form>';
                       };
                  ?>

                    And where's the rest of the code that outputs a valid HTML document? For example, where's the <html> tag, or <head>, or <body>... ?

                      That's it, that what I was missing.
                      I was wrongly assuming that the other HTML tags where somehow automatically generated since my page was working.
                      I have now added everything, including the CSS sheet and all is well. Thank you 🙂

                        Write a Reply...