468,272 Members | 2,036 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,272 developers. It's quick & easy.

CSS and PHP

Sorry, I am a Java programmer and very new to php and was wondering with
these questions. How do you typically integrate CSS into a PHP script.
Do you embed it or reference a external CSS file? Have an include script
to dynamically generate it. How do you have it work with a HTML FORM?
Sorry, I have no clue as of yet. I have just started to research it.

I have written the php code for my quotation test site. I want to start
to format it via css. I have just built and playing with it at
http://ichbinquotations.awardspace.com

Also, any tips and Preferred Resources?

--
Thanks in Advance... http://ichbin.9999mb.com
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
__________________________________________________ ____________________
'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Oct 26 '06 #1
8 1122
Rik
IchBin wrote:
Sorry, I am a Java programmer and very new to php and was wondering
with these questions. How do you typically integrate CSS into a PHP
script. Do you embed it or reference a external CSS file? Have an
include script to dynamically generate it. How do you have it work
with a HTML FORM? Sorry, I have no clue as of yet. I have just
started to research it.
PHP is not linked to CSS in any way.
PHP generates/handles code, and spews back what's asked of it. If you want
the output html documents, just make sure there's a correct link in the
header like with static HTML documents.

Both HTML & CSS are rendered in the client's browser, so all you have to do
is provide the correct output.
--
Rik Wasmus
Oct 26 '06 #2
It is generally a good idea to link to an external CSS file. Having
all your pages point to one file makes changes much easier than having
to change it in every file.

But this is a basic html/css issue, not very closely related to php.

Oct 26 '06 #3
Michael Vilain wrote:
In article <te********************@ptd.net>, IchBin <we******@ptd.net>
wrote:
>Sorry, I am a Java programmer and very new to php and was wondering with
these questions. How do you typically integrate CSS into a PHP script.
Do you embed it or reference a external CSS file? Have an include script
to dynamically generate it. How do you have it work with a HTML FORM?
Sorry, I have no clue as of yet. I have just started to research it.

I have written the php code for my quotation test site. I want to start
to format it via css. I have just built and playing with it at
http://ichbinquotations.awardspace.com

Also, any tips and Preferred Resources?

CSS and HTML are the "output" of whatever sever-side programming
language you're using to generate that output. If you're using some
sort of templating system, use it's constructs. Otherwise, this is up
to how you've designed the program.

You can buy lots of books on HTML and CSS from lots of places. I like
the O'Reilley and Sitepoint offerings.

YMMV.
Thanks for all of your replies...

For this particular group of scripts I am not using any templating.
I should have been clearer. Guess my question was not about the natures
of CSS\HTML\PHP. I understand those.

Looking for tips on usual way to tightly couple them to my advantage.
PHP is not linked to CSS but they can be tightly coupled. PHP works on
the server side but can also present the client side presentation. In
this presentation I wanted to interlace HTML, CSS and PHP code.

Is this a viable approach? I realize their are no standards in PHP but
their must be more efficient ways, that have floated to the top, to
approach what I am trying to do..? Or is this the right approach?

This maybe a basic html/css issue but when I tightly couple it with PHP
I see questions?

Maybe with this perspective this would be a better way to ask my
questions. :shock:

My sources for documentation has been the W3C Recommendations for HTML
and CSS.

--
Thanks in Advance... http://ichbin.9999mb.com
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
__________________________________________________ ____________________
'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Oct 26 '06 #4
Rik
IchBin wrote:
For this particular group of scripts I am not using any templating.
I should have been clearer. Guess my question was not about the
natures
of CSS\HTML\PHP. I understand those.

Looking for tips on usual way to tightly couple them to my advantage.
PHP is not linked to CSS but they can be tightly coupled. PHP works on
the server side but can also present the client side presentation. In
this presentation I wanted to interlace HTML, CSS and PHP code.
So? Make your CSS (either dynamic with PHP, or a static CSS file), spit out
the HTML with PHP, et voilá.
Is this a viable approach? I realize their are no standards in PHP but
their must be more efficient ways, that have floated to the top, to
approach what I am trying to do..? Or is this the right approach?
We're not sure what you're trying to do. You have a couple of pages, with
HTML output from PHP, and want to use CSS for them. There is no difference
in static/dynamic output as soon as it's at the client....
This maybe a basic html/css issue but when I tightly couple it with
PHP I see questions?
WHAT do xou couple with PHP? HOW? It's pretty much a one way street PHP ->
HTML (possibly CSS), that's not a coupling IMO.
--
Rik Wasmus
Oct 26 '06 #5
Rik wrote:
IchBin wrote:
>For this particular group of scripts I am not using any templating.
I should have been clearer. Guess my question was not about the
natures
of CSS\HTML\PHP. I understand those.

Looking for tips on usual way to tightly couple them to my advantage.
PHP is not linked to CSS but they can be tightly coupled. PHP works on
the server side but can also present the client side presentation. In
this presentation I wanted to interlace HTML, CSS and PHP code.

So? Make your CSS (either dynamic with PHP, or a static CSS file), spit out
the HTML with PHP, et voilá.
>Is this a viable approach? I realize their are no standards in PHP but
their must be more efficient ways, that have floated to the top, to
approach what I am trying to do..? Or is this the right approach?

We're not sure what you're trying to do. You have a couple of pages, with
HTML output from PHP, and want to use CSS for them. There is no difference
in static/dynamic output as soon as it's at the client....
Actually it is only one page that is presented. Sorry I have not
explained what I am going to try to do. I have a lot of other objects I
want to add to this page. Guess it is my lack of knowledge of CSS and
the serial output from the server and how to place the data on my one
html output. I am looking at XMLHttpRequest but I hear a lot from others
that you should not use javascript because users can set it of in their
browser. Then again their seems to be a lot of Javascript running on the
net. Little confusing on my part.
>
>This maybe a basic html/css issue but when I tightly couple it with
PHP I see questions?

WHAT do xou couple with PHP? HOW? It's pretty much a one way street PHP ->
HTML (possibly CSS), that's not a coupling IMO.
I guess I see it as coupling because the PHP print\echo statements are
passing the front end along with the php server side data output.

--
Thanks in Advance... http://ichbin.9999mb.com
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
__________________________________________________ ____________________
'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Oct 26 '06 #6
IchBin wrote:
Sorry, I am a Java programmer and very new to php and was wondering with
these questions. How do you typically integrate CSS into a PHP script.
Do you embed it or reference a external CSS file? Have an include script
to dynamically generate it. How do you have it work with a HTML FORM?
Sorry, I have no clue as of yet. I have just started to research it.

I have written the php code for my quotation test site. I want to start
to format it via css. I have just built and playing with it at
http://ichbinquotations.awardspace.com

Also, any tips and Preferred Resources?
As others have noted, there really isn't a close tie between PHP and CSS.

PHP just creates HTML and sends it to the client. Nothing more, nothing
less.

Build a sample static page first, and get it to look like you wish. You
can get help from alt.html and/or alt.html.css.

Then go back and replace the appropriate static elements with PHP
generated code. They should look exactly the same.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Oct 27 '06 #7
NC
IchBin wrote:
>
How do you typically integrate CSS into a PHP script.
Do you embed it or reference a external CSS file?
Either or both; just like in HTML. Additionally, PHP allows you
to generate CSS dynamically.

Let's say your HTML/PHP/whatever files have this tag:

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

Then, inside stytle.php, you may write, for example:

header('Content-Type: text/css');
switch ($_GET['palette']) {
case 'blueandyellow':
$b = '#0000ff';
$c = '#ffff00';
break;
case 'greenandsilver':
$b = 'green';
$c = 'silver';
break;
default:
$b = '#ffffff';
$c = '#000000';
}
echo <<<EOCSS
body {
color: $c;
backrgound-color: $b;
}
<!-- Many other styles go here -->
EOCSS;

Then, you can switch the color palette (or any other attributes
derfined
by the stylesheet) is as easy as going from

<LINK rel="stylesheet" href="style.php?palette=blueandyellow"
type="text/css">

to

<LINK rel="stylesheet" href="style.php?palette=greenandsilver"
type="text/css">

The standard recommendation is to put as much style information
into an external stylesheet as possible and suggest that the clients
cache the stylesheet. This way, the stylesheet gets requested only
once.
Also, any tips and Preferred Resources?
The CSS Specificatoin is your friend:

http://www.w3.org/TR/CSS2/

Cheers,
NC

Oct 28 '06 #8
IchBin wrote:
How do you typically integrate CSS into a PHP script.
Do you embed it or reference a external CSS file?
Always, single and external (and, other styles for other media(say,
print) and alternate styles).

<snip>
Also, any tips and Preferred Resources?
The current trend in web dev is the templating via CSS (esp, with
XHTML)--in which the position of HTML elements are "controlled" with
CSS. For the real world example, check
<http://www.mezzoblue.com/zengarden/alldesigns/(you'll see, the HTML
remains same, but only the CSS file is changed externally).

For beginner <http://www.webdesignfromscratch.com/and then lot of
links at mozilla dev corner like
<http://developer.mozilla.org/en/docs/Writing_Efficient_CSS>

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Oct 29 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by William C. White | last post: by
2 posts views Thread by Albert Ahtenberg | last post: by
3 posts views Thread by James | last post: by
reply views Thread by Ollivier Robert | last post: by
1 post views Thread by Richard Galli | last post: by
4 posts views Thread by Albert Ahtenberg | last post: by
1 post views Thread by inderjit S Gabrie | last post: by
2 posts views Thread by Jack | last post: by
3 posts views Thread by Sandwick | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.