does the PHP code run independant of CSS?

Newb question about how PHP works with formatting on a page..

If I have PHP code developed for me by a web programmer.. for siteA, can I take that same code and use it with siteB, which has a different "look and feel" to it then siteA ?  i am trying to understand how php works in regards to the look and feel of a page.. tables, color and font schemes, etc...

I want to have a Portfolio section developed for a web site that would show Completed Jobs, and Work in Progress on siteA
Assuming the contract with the developer is written so that this is possible contracturally, I would like to then take that code and use it on siteB that will also have a Portfolio section....


Who is Participating?
rdivilbissConnect With a Mentor Commented:
The ideal would be that your layout (CSS) is separate from your content (HTML)

If your contractor does not embed layout in the HTML it will be relatively simple to change the style for a different site.  Probably the best example I know of is CSS Zen Garden, where one site has been customized with different styles from many different web designers. ( It is amazing to see how dramatically different a site can be just by changing the CSS.

With CSS there are three ways to refer to the markup so you can assign a style.  By HTML tag, by the element's ID and by the element's class.

Your contractor will need to make sure that the underlying HTML properly exposes the various HTML elements to CSS by proper use of one of those three methods.  As long as that is the case, you should be okay.

One way to help specify what you expect, is to specify that the HTML validates properly to HTML 4.01 strict recommendations and uses no obsolete or depreciated tags.  (  You should also specify that except for columner data (such as a stock chart, or other data grid) that no tables be used to achieve page layout.

All of that background and no mention of PHP????

PHP is a server side scripting language.  It has nothing to do with output, except what the author causes it to write.  So if you specify the above, any output rendered via PHP will need to comply as well.  CSS does not take effect until the page is rendered.  Anything done with PHP will be completed before the CSS becomes effective.  (e.g. at that point you simply have HTML output, the PHP processing is complete.)

Good Luck,
rdivilbiss's answer summarizes the factors involved in a PHP, HTML (or XHTML), and CSS solution.

PHP itself can control server-side output, meaning it can write HTML files (and CSS and JS files for that matter)

depending on the contents of these HTML files, you might be able to control what the pages look like... but to varying degrees.

CSSgarden is an example of a place where this is done powerfully.  Depending on whether you just want to change colors or whether you want to change entire layouts, you might be creating quite a headache in terms of writing HTML that will be completely re-arrangeable via CSS.

one major problem is that even today, much of the code out there is formatted in tables.  And I, for one, have never been able to completely control every aspect of the organization of a page that's table based.  if you're lucky, they'll use DIVs for most things, which will give you more freedom of arrangement (if that's what you're looking for).
CSS defines styles for a browser (IE, Firefox, Netscape). Anything that is processed at the browsers end (your computer) is called "client side" so CSS would fit in this definition.

But PHP isn't, it is server side: anything that is processed at the servers end (where the website is kept). The servers preprocesses the PHP code, and then it is sent to your browser in HTML format, thats why it is impossible to view a PHP code on a browser (all you will see is HTML).

So when using SiteA PHP code in SiteB, other parameters rather than CSS should be considered: PHP default configurations (example..cookies and sessions are available on SiteA but not on SiteB), database connectivity and configuration (if SiteA php codes connects to a MySQL engine, then SiteB must have it too unless there is a configuration file where a Database is defined and can easily be switched).

The only dependance I can see between PHP and CSS would be for example that the programmer, knowing that most users (clients) will be using IE or Netscape, outputs CSS code using PHP:

echo "<STYLE>   A:hover......"  

I understand that the hover attribute works with Explorer and Netscape 6.x, so using a different browser might result a different looking page.

You make search through Google for CSS compatibility among browsers.

if your PHP code works smoothly, CSS becomes it only gives better aesthetic looks.


Thank you.  Good luck with your project.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.