Is it possible to take a web page that lets say has CSS that makes the header position:fixed
, then use php and use either cURL
or file_get_contents
, and apply my own CSS file to change that header to position:absolut
?
Asked
Active
Viewed 1,839 times
0

Jared
- 471
- 1
- 3
- 17
-
I would be putting the page then inside an iframe. – Jared Feb 13 '14 at 15:31
-
Sure you can do that but remember that you also have to rewrite every relative path used in the html. Every src, href and posibly javascript and css attributes have to potentialy be rewritten, not an easy task – Jesper Blaase Feb 13 '14 at 15:35
-
All PHP does is put an HTML file together and send it to the client. So eg file_get_contents gets the HTML from another page and puts it in yours, then sends it to the client. CSS is clientside which means you can override any style – RobinvdA Feb 13 '14 at 15:37
-
You can't over-ride styles in an iFrame, since an iFrame doesn't actually have any styles...it's a page unto itself with it's own style associations. – DA. Feb 13 '14 at 15:47
-
1Here's your answer: It can be done if a) the content of the iFrame is coming from the same domain as the parent page and b) you use JavaScript http://stackoverflow.com/questions/217776/how-to-apply-css-to-iframe?rq=1 – DA. Feb 13 '14 at 15:48
-
@DA. Hm i missed the iFrame part – RobinvdA Feb 13 '14 at 15:52
-
@DA. I was trying to take an eternal site, use file_get_contents and display that page on my host. Then use a CSS page and then take the page with file_get_contents and put it on another page inside an iframe. – Jared Feb 13 '14 at 15:56
-
@Jared so you are essentially screen-scraping? If so, the iFrame is moot, as it's now your file on your server and you can do with it as you see fit (at least technically speaking...there may be legal issues, but that's another story...). In that case, you simply want to inject your over-ride CSS links into the file you are inserting into the iFrame. – DA. Feb 13 '14 at 15:58
1 Answers
0
You can do it using some JavaScript to identify whether or not your page is in an iframe (Look here for more information: How to identify if a webpage is being loaded inside an iframe or directly into the browser window?).
Then, you could simply insert inline CSS based on this, make the page import different CSS files, etc.

Community
- 1
- 1

Nick Louloudakis
- 5,856
- 4
- 41
- 54