1

is there a way to style a php file with css so I can use border,padding, align and teother various

will this work or not if i added to the php or will i need functions for using this

<link rel="stylesheet" type="text/css" href="style.css" />
3
  • so i can oly style outside the php tags Commented Nov 29, 2010 at 8:53
  • 1
    that's exactly the case, you can only style the html elements on your page (which is created using php) Commented Nov 29, 2010 at 8:54
  • 3
    Only the output of your PHP script matters, i.e. what you see in your browser when you choose View > View Source. Commented Nov 29, 2010 at 8:55

5 Answers 5

6
  1. You cannot and probably will never be able to style a PHP file using css. What you want to style using css is the html content created using PHP and/or javascript! That is because styling takes place on the client machine in order to show things to the user while php gets executed on the server machine in orderf to produce code which will be readable by a browser.

  2. <link rel="stylesheet" type="text/css" href="style.css" /> will work if the file style.css is found at that location (i assume your are using valid css definitions in your file)

Sign up to request clarification or add additional context in comments.

Comments

4

You can use css to style HTML files. PHP generates HTML (or not) and you cannot style PHP files.

Comments

4

PHP doesn't know or care about CSS, and neither does it need to.
PHP runs on the server and does whatever it does, which should result in an HTML document.
This HTML document is send to the browser.
Only the browser cares about CSS, and it doesn't care whether an HTML document was just a file on the server's hard disk or whether it was created by PHP or magic fairies.


If the document the browser receives is an HTML document, you can use CSS with it. PHP has absolutely zero influence on this.

1 Comment

Additionally, it may result in any kind of file other than HTML, if you tell it to output such; For example, a PNG image.
3

You don't style PHP with CSS. What's there to style? It's all just server-side code that generates HTML. You style HTML with CSS, not PHP.

Comments

-1

If you are looking for a way to define styles in variables i.e. colour etc and make it easier to generate css try http://lesscss.org/

It's what I use to make css edits faster instead of copying and pasting.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.