Zaloguj | Zarejestruj | FAQ
Anonymous

Can I use PHP in CSS style file?

+ Odpowiedz

Posty: 7 Strona 1 z 1


Can I use PHP in CSS style file?

przez zjing129 » Cz maja 10, 2012 1:11 am

For example, I would like to set a background image which changes with the day of the week, e.g., "pic1.png" for Monday, "pic2.png" for Tuesday, "pic3.png" for Wednesday, etc. It seems that the following command in CSS file does not work.

body{
background-image: url('pic<?php echo date('w');?>.png');
}


What is wrong? Thanks.
Avatar użytkownika

zjing129

  • Posty: 4
  • Dołączył(a): Cz maja 10, 2012 1:00 am

Re: Can I use PHP in CSS style file?

przez XainPro » Cz maja 10, 2012 6:16 pm

in external css file no you can not but in internal document or embended CSS yes you can...
place it in the head section of your document it should work ...
Kod: Zaznacz cały
<html>
<head>
<title>title</title>
<style type="text/css">
hr {color:sienna;}
p {margin-left:20px;}
body {background-image:url("<?php echo......etc?>");}
</style>
</head>
<body>
The Body
</body>

</html>
Avatar użytkownika

XainPro

  • Posty: 3933
  • Dołączył(a): Pt lut 17, 2012 8:10 pm

Can I use PHP in CSS style file?

przez jin1234i » Śr maja 23, 2012 8:31 am

This means the style sheet can be renamed from style.css to style.php. An addition to CSS is pending that will permit the use of CSS variables.


Tømrerfirma
Avatar użytkownika

jin1234i

  • Posty: 1
  • Dołączył(a): Cz maja 17, 2012 7:20 am

Re: Can I use PHP in CSS style file?

przez XainPro » Śr maja 30, 2012 11:57 am

no if you use external CSS file then it could not have the PHP code in it but in internal style sheet you can use php code in it.
There could be a hack for this but in normL WAY NO YOU can not use style.php as a CSS file :)
Avatar użytkownika

XainPro

  • Posty: 3933
  • Dołączył(a): Pt lut 17, 2012 8:10 pm

Re: Can I use PHP in CSS style file?

przez webbolato » Cz lut 07, 2013 12:59 pm

Yes you absolutely can, with a little bit of .htaccess and header hackery :-)

How-to via the following links:
http://css-tricks.com/css-variables-with-php/
http://net.tutsplus.com/tutorials/php/supercharge-your-css-with-php-under-the-hood/
Avatar użytkownika

webbolato

  • Posty: 1
  • Dołączył(a): Cz lut 07, 2013 12:55 pm

Re: Can I use PHP in CSS style file?

przez comport9 » Cz lut 21, 2013 12:27 am

Take this for what it's worth, but I remember embedding PHP in my CSS file and it worked. But only for a SHORT amount of code. I don't know what was going on, but it seemed like it would read some of the code, but not the rest.

However, as Xian said, it's not necessary, and it's probably best just to put the PHP style part in the PHP/HTML file rather than the CSS.
Avatar użytkownika

comport9

  • Posty: 28
  • Dołączył(a): N lis 04, 2012 5:35 pm

Re: Can I use PHP in CSS style file?

przez RyanKnol » Cz lip 30, 2015 10:35 pm

how is this what google finds for me?

Anyone still looking can use THIS..

http://westcoastmarketing.ca/sass-is-fat-use-php-code-in-css-files/
Avatar użytkownika

RyanKnol

  • Posty: 1
  • Dołączył(a): Cz lip 30, 2015 10:33 pm


+ Odpowiedz

Strona 1 z 1