I have a stylesheet link that looks like below:
<link rel="stylesheet" href="/example/get_page.php?location=bla.css" id="main_ss" />
get_page.php just gets a URL using file_get_contents():
if (isset($_GET['location'])) {
echo file_get_contents('/example/styles/' . $_GET['location']);
}
I can see that the stylesheet file is being fetched properly (for example the text of the file is showing in firebug when I expend the link tag) but for some reason it is ignored by the browser. If I just fetch the CSS file directly of course everything works.
The code can be seen here: www.specman-verification.com/example/bla.html
Any leads? I'm at loss here.
Add the Content-type header like this (do this before you output anything):
header("Content-type: text/css");
Your code is just trying to load the script get_page.php. To load the CSS file you need:
<link rel="stylesheet" type="text/css" href="/example/bla.css" />
(or similar depending on the actual path to your CSS file). In other words the href attribute needs to specify the path to your spreadsheet file, not the HTML page file.
You need to do it the right way. I understand what you're doing here. You need a good mechanism to dynamically load external CSS and have the result display normal html in the browser output.
Follow the instructions on this url: http://www.warpconduit.net/2009/05/12/dynamically-load-css-and-js-files-using-php/
This will at least get you to have a mechanism to load external css file with php dynamically. You're definitely missing steps in your code.
Related
I'm recently doing a website for a school project. In order to organize my work, I create a tree folder that keeps all the work organized. It is similar like this:
Back-Office
Pages
Home
home_test1.php
home_test2.php
home_test3.php
Login
Folder_Login
login.php
logout.php
Resources
CSS
style_home.css
style_navbar.css
style_footer.css
JS
script_home.css
script_navbar.css
Sections
navbar.php
footer.php
After all, with the require() method available in PHP, I want to call the "navbar.php" file to the "home_test1.php", "home_test2.php" and "home_test3.php", but the CSS style that is connected with the file "navbar.php" ("style_navbar.php"), doesn't display.
I've tried to change the path of the CSS style in the file "navbar.php" when I require() to the other file ("home_test1.php") and the CSS style shows up, but wont display in other file with a different path. How can I make this work dynamically? Sorry for long post and bad English grammar.
Thank you in advance.
You need to set your css and js files with absolute path instead of relative path
$dir = realpath($_SERVER["DOCUMENT_ROOT"]);
<link rel="stylesheet" href="<?php echo $dir.'/resources/css/style_home.css'; ?>" >
Without physically seeing you code it is quite hard to debug however there is an "obvious" answer that I'll suggest as a starting point.
The important thing to remember is that PHP and HTML are processed in completely different places. PHP executes on the server and should be used to build a full HTML "document" which it gives to the client/browser. The client/browser then reads the document provided and renders it according to HTML standards.
Calling require() will tell PHP to get the file and slot its contents directly where it was called and as it is a CSS file it will need to sit within the style tags. With a lot of modern browsers, if you use require on a file outside of the html tags, the content will be dumped at the top of the screen or simply ignored due to invalid syntax.
Alternatively if you would like to simply use tell the browser to include the CSS file, you could use the good old method of using <link rel="stylesheet" href="/path/to/file">. It's good to know when and when not to use PHP.
PS: You have .css files in your JS directory.
In PHP, there is a global variable containing various details related to the server. It's called $_SERVER. It contains also the root:-
$_SERVER['DOCUMENT_ROOT']
<?php
$path = $_SERVER['DOCUMENT_ROOT'];
<link rel="stylesheet" href="<?php echo $path.= '/Resources/CSS/style_navbar.css';?>" />
?>
I have two HTML templates. And I buffer them into php email using ob_start() and ob_get_clean(). However, one can be sent without any problem while another has no images in the email body. Can anyone find what the problems are? Here are the two templates:
the good one: http://www.emoceanstudios.com.au/good.txt
the bad one: http://www.emoceanstudios.com.au/bad.txt
I have tried to use absolute path for images, and tried to use img tag instead of div with background image, but they don't work.
How about inline image? you can convert the img into data first. http://www.websiteoptimization.com/speed/tweak/inline-images/
You can try uploading images to cloud and use them from there....I am not sure...but may be this helps..!!! Also, remember putting ob_flush() in such cases.
You are using CSS in bad.txt file which path you have mentioned is given below.
link href="quote.css" rel="stylesheet" type="text/css"
so please mentioned your path with http://www.emoceanstudios.com.au/CSS/quote.css it is just a example but please provide full path to get Template as you want.
link href="http://www.emoceanstudios.com.au/CSS/quote.css" rel="stylesheet" type="text/css"
I have an PHP/HTML main page, in which I include different other PHP files (I include them within the body of the main page).
What if I want to include a CSS stylesheet into only ONE of the included file?
What if that included file is a PHP-only file? (that is, it doesn't have those <head> tags, where the stylesheet reference is supposed to be)
What happens if I put "head" tags into a PHP file that is included in the body of the main page? I am wondering if putting head tags in the middle of the HTML body tags could cause problems at all, or at least with certain browsers.
Think of it this way, after all of you includes you still get one html file at the end of it. If you are including files in the body of your document, it should only contain tags that fit within the body, not html, head, title, body, etc. Your css file should be loaded in the of the main doc. Something like this
<html>
<head>
<title>Title</title>
<!--
css and js here
-->
</head>
<body>
<!-- php include here ---->
<div>content</div>
</body>
</html>
So after your includes the html should still be valid. you can check that here http://validator.w3.org/
EDIT:
You can included as many css files as you want anywhere in the document but the overall structure should still be as above. But try to consolidate your css files as much as possible. Every external file is one more request the browser has to make, and can slow the load time if you have a lot.
You can add style tags in the middle of your html, it's bad behaviour, but you can and it'll work. So, you can only import css you need depending on what you include to your main php. But, you don't have to put head tags for that.
It is ok if you will put you link your css file in any of your files, also if your file is php, you can put your css before or after the php tag. But for me its better to include your css file on your main page as long as you have a unique design or style for a unique element or id on the file that you want to design.
<link href="style.css" type="text/css" rel="stylesheet">
<?php
Content of your php file here
?>
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" />
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.
<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)
You can use css to style HTML files. PHP generates HTML (or not) and you cannot style PHP files.
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.
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.
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.
I am having difficulty trying to get modernizer to run with codeigniter.
this is what I've done so far.
downloaded Modernizr and renamed the file modernizr-1.5.min.txt to modernizr-1.5.min.js
put the JavaScript file in the same directory as my header file is: apppath/views/tops/
included the file in my headings <script src="modernizr-1.5.min.js"></script>
included this in my HTML element <html class="no-js">
just to preserve my sanity I put the JavaScript file modernizr-1.5.min.js in my views directory and in the application directory.
I am getting absolutely zero response when I read my page source to see if the has been replaced with the elements that my browser covers the wave modernizr is supposed to work. I have tried this using Firefox and chrome as far as reading the source.
any suggestions? Thank you in advance
why would you put javascript files ito the view folder of your app? i would rather use this path "/media/javascripts/modernizr.js" and then <script src="/media/javascripts/modernizr.js"></script> link it like that. the view folder is only for templates. other thing is that you will never see the changes that javascript does to your page in the pagesource. because it only shows you what html the browser received. and javascript starts to work after the browser received the html. you need to install firebug to see the "live" dom.