Can I include php in css stylesheet?

Questions and tutorials related to Cascading Style Sheets *all versions*

Moderators: egami, macek, gesf

Post Reply
IChaps
New php-forum User
New php-forum User
Posts: 115
Joined: Tue Mar 01, 2016 3:07 pm

Tue Apr 26, 2016 1:52 pm

Hello.

I'm currently looking into the possibility of using css.
At present I've just using TopStyle's css software and got a new Style Sheet from template.

I'd just like to ask if I can include a php file, and if so how do I go about it please.
I've tried using include and the line [<!--webbot bot="Include" U-Include="block1.php" TAG="BODY" --> ] and
iframe both in html but neither work.

I can't remember if I should use something else.

Thank You
Ian.

User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 686
Joined: Mon Feb 22, 2016 5:52 pm

Tue Apr 26, 2016 3:23 pm

If your server is set up to parse css files then you can, otherwise you will need to do something like this:

Code: Select all

<link rel='stylesheet' type='text/css' href='styleheet.php' />
An example could be

Code: Select all

<?php
header("Content-type: text/css; charset: UTF-8"); # note this line is before the echo
$font-colour = #89a;
echo <<< css
html {
  font-size: 16px;
  color: $font-colour;
  margin: 0;
  padding: 0;
}
css;

The line that you are trying to insert is pointless, css is used for displaying html elements - nothing else - I would think that you need to do something else to achieve whatever it is you are trying to achieve.

HTML and CSS do not process as such, they are mostly static*. PHP will process on the server side and JavaScript will process on the client (browser) side.

* There are exceptions to this, but the processing that can be done is fairly limited / restricted and certainly not in the same way that you are looking at.

IChaps
New php-forum User
New php-forum User
Posts: 115
Joined: Tue Mar 01, 2016 3:07 pm

Wed Apr 27, 2016 8:28 am

Hello Hyper,

Thank you for your reply.

Kind Regards
IChaps.

IChaps
New php-forum User
New php-forum User
Posts: 115
Joined: Tue Mar 01, 2016 3:07 pm

Wed Apr 27, 2016 10:23 am

Hello Hyper,

What I've attempted to do is,

create a table with 1 row and 3 columns.
In:-
Column 1: include a menu created in php
Column 2: include another php file.
Column 3: include either a graphic or another php file.

I've attempted to create a 3 blocks side by side, but was unable to achieve this, that's why I started using css.

Thanks.

User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 686
Joined: Mon Feb 22, 2016 5:52 pm

Wed Apr 27, 2016 10:53 am

What I suggest is that you do a beginners tutorial in html and css before you carry on with php, there are fundamental differences between each of them and short answers to will not help you.

IChaps
New php-forum User
New php-forum User
Posts: 115
Joined: Tue Mar 01, 2016 3:07 pm

Wed Apr 27, 2016 11:41 am

Thank you very much.

IChaps
New php-forum User
New php-forum User
Posts: 115
Joined: Tue Mar 01, 2016 3:07 pm

Sat Apr 30, 2016 2:26 pm

Hello Hyper. :)

Hope you are ok.
Just a short note to say I've achieved what I wanted to do.
It was a minor glitch in my css software setup, and I've also using iframe which I forgot about at the start.

Thank you for your replies and help.
Kind Regards
IChaps.

User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 686
Joined: Mon Feb 22, 2016 5:52 pm

Tue May 31, 2016 10:11 am

I'm not sure what you are asking:

Question:-Do you need to know php to learn css?
Answer:-No.

Question:- Do you need to know css to learn php?
Answer:- Strictly speaking no, in practice you do need to know css & html if you want to create web pages with php.

Post Reply