1

I've been searching about this for a while with no luck, I'm just curious if this is possible.

Is it possible to include CSS rules directly in a php file with no HTML code?

img {
  background: 0px 0px / 100% 100% no-repeat scroll rgb(12, 12, 12);
  height: 100%;
  width: 100%;
  position: fixed;
}

I just have this piece of code and I don't think would be necessary to create a .css file to include just this small piece of code, otherwise I will create the css file.

VaTo
  • 2,936
  • 7
  • 38
  • 77
  • Unless is a one page site, i recommend to use a external file, but answering your question, you can either use echo, or close php tag (?>) write it inside style tag and open again ( – Vertig0 Jun 01 '15 at 16:44
  • Please search for things like this before you post: http://stackoverflow.com/questions/3483213/how-can-i-include-css-in-php And: http://stackoverflow.com/questions/25336229/adding-css-to-php – Matt C Jun 01 '15 at 17:01
  • @MatthewC Like I said in my post I didn't find it with luck. The ones you are pointing me to say that I can include a CSS file which is what I don't want to do. – VaTo Jun 01 '15 at 17:04

3 Answers3

1

You can put it into your PHP file using <style> tag:

<style>
    img {
        background: 0px 0px / 100% 100% no-repeat scroll rgb(12, 12, 12);
        height: 100%;
        width: 100%;
        position: fixed;
    }
</style>

Or directly to image into style attribute.

<img style="position: fixed; width: ...">
pavel
  • 26,538
  • 10
  • 45
  • 61
  • It doesn't matter. ` `. Or, of course, you can echo it, like `echo '';`. Many ways how to achieve that. – pavel Jun 01 '15 at 16:47
0

Yes, this is just an "inline CSS" policy

rICh
  • 1,709
  • 2
  • 15
  • 25
0

PHP runs on the server and css/html/javascript all run on a web browser, so you can't have the css in between and I'm afraid you'll need a little html, but just a little

it should look like this:

<?php <php code> ?>
<style>
    img {
        background: 0px 0px / 100% 100% no-repeat scroll rgb(12, 12, 12);
        height: 100%;
        width: 100%;
        position: fixed;
    }
</style>
<?php <more php code if you like> ?>
Ian Overton
  • 1,060
  • 7
  • 17