I have a big prob. We have a site that was working just fine but I was doing some fine tuning and somewhere along the line i messed things up. possibly in the .htaccess file.
My problem is that my css style sheet doesn't load nor do my images. ahh! They are all there.
I emptied my .htaccess file and deleted my robots.txt just to eliminate any blocking but that didn't fix it.
I validated my css file with The W3C CSS Validation Service and it said:
file not found: http://easybuildingproducts.ca/www.easybuildingproducts.ca/style.css
I feel like it has something to do with the fact that the URL is duplicated. It does that now when i click a link to any of my pages. It should be either or not both those links together. Is it possible a google cached my .htaccess or robots.txt when there was a potential redirect error? Is there a loop happening somewhere?
I was in the midst of making a custom 404 error page when this all went down.
www.easybuildingproducts.ca
Easy fix
<link href="www.easybuildingproducts.castyles/inside.css" rel="stylesheet" type="text/css">
That needs to be either one of the following
<link href="/styles/inside.css" rel="stylesheet" type="text/css">
or
<link href="http://www.easybuildingproducts.ca/styles/inside.css" rel="stylesheet" type="text/css">
I looked at the actual website source to find this example. there are quite a lot like it
Change the href to "/style.css" instead of writing your full domain out. Do the same kind of thing for all other resources that failed to load, too.
This will fix your problem, and it will also make your markup compatible if you decide to migrate to a different dsomain name in the future.
Your resources aren't being loaded (css, js, jquery, etc). Take a look at the screenshot taken from my Chrome Dev Tools > Sources tab:
This is because of your resources' file paths. It is definitely not a good idea to reference all of your resources with "www." in the file path.
Change
<link href="www.easybuildingproducts.castyle.css" rel="stylesheet" type="text/css" />
into
<link href="/castyle.css" rel="stylesheet" type="text/css" />
Related
I use XAMPP to create PHP pages and test them locally, but have an issue with the CSS styles not being applied.
When I browse to http://localhost/example/index.php I get the correct PHP page output, but it is unstyled.
When I browse to file:///c:/xampp/htdocs/example/index.php I get the page and it is styled so I know that my CSS links are not the problem.
Does anybody know what's happening and how to fix it?
since you didnt provide any code, I suspect you are using absolute path instead you should use relative path
suppose below is your structure
index.php
css
-- main.css
then you should link you css like
<link type="text/css" href="css/main.css" rel="stylesheet" />
hope it helps
I am baffled by this and I am hoping someone can indicate at a highlevel where my thinking is faulty.
I have a simple PHP programme
- index.php includes a file /common/header.php
- header.php links to the stylesheet.
Issue 1 which I think has baffled other people but I have not seen a reply that answers the question directly.
If I put the style sheet in the root folder (in the same place as index.php), then I can link to the file without a path
<link rel="stylesheet" type="text/css" href= "style.css" />
The point is that the style sheet is relative to index.php NOT the the header.php when it is included in index.php. Is this correct?
Issue 2 is really odd. When i put the file in a folder I can link to it as
<link rel="stylesheet" type="text/css" href= "/common/style.css" />
or
<link rel="stylesheet" type="text/css" href= "common/style.css" />
or
<link rel="stylesheet" type="text/css" href= "styles/style.css" />
and so on.
BUT, this fails if I name the folder css. Anyone?
There is one other point which might be relevant. I am using WAMP and this website is set up with a virtual host.
That is, I have the host set up in the hosts file in Windows/System 32 and in the Apache httpd.vhosts.conf file.
That means that the index.php file is in the root directory and /common/style.css is functionally equivalent to common/style.css.
Any tips for understanding this would be much appreciated. thanks.
First of all, a relative link to a path in html is completely different from one that is in PHP.
in PHP your document root might be /var/www/example/ while in html this could be http://www.example.com/
the client browser that reads the HTML as no idea of where your html is echo'd location wise other then the entry script (in this case : http://www.example.com/index.php)
So if i just refer to
<link rel="stylesheet" type="text/css" href= "/css/style.css" />
and put the stylesheet in /var/www/example/css/style.css then it doens't matter what the location of header.php is and where it is echo'ed, as long as it is in relation the to entry script (index.php in this case)
Issue 1:
Your problem is not one of PHP, but rather of HTML. CSS is applied by the browser after it has received the HTML source. So when your index.php is the script that outputs the content, all resources your reference in your html will be relative to the path this file is in.
Issue 2:
the difference between
<link rel="stylesheet" type="text/css" href= "/common/style.css" /> and <link rel="stylesheet" type="text/css" href= "common/style.css" /> is that version 1 will only work as long as /common resides in the root of your web server. It's an absolute path (starting with /) while version 2 is relative and would also work if your file was /xyz/common/style.css.
I have no idea why this should not work with the name css though. You should probably retry this.
Thanks everyone. That was fast.
To sum up the include problem which I suspect many people have. The path to the stylesheet must be relative to index.php not header.php.
The other problem I have solved. Some files were inadvertently copied into C:/wamp/www, i.e., the normal root. I cleaned all those out and the odd problem of refusing to play with a folder call /css went away. So this is a two fold problem beginning with 1. mess and 2. being something to do with the virtual host not working properly. At least the fog has lifted. Thank you all.
And for DarkMukke, "Anyone?" is phatic. It is a social nicety most likely used by newbies to convey respect when they realise the problem is as much to do with their own fog as anything technical. Or in geek-speak, the newbie is tipping their hat to anyone who will give them 5 mintues to set them straight.
Thanks everyone.
I am stumped. I am using includes to import a style sheet. If I add a new style to the style sheet, generated pages will not display ANY of the new css. If I change an old css rule it WILL display the change. I thought it might be a cached file of some kind, but I have cleared the cache in all testing browsers and the problem persists.
At first I thought it was a WAMP issue, but the problem happens when I move it all live as well so now I am thinking I am doing something wrong with the includes....
<link rel="stylesheet" type="text/css" href="css/foundation.css">
<!-- Included Custom Overides -->
<link rel="stylesheet" type="text/css" href="css/Custon_Foundation_Overides.css">
<!-- Supersizer CSS -->
And this is simply my include...
<?php require("Includes/HEADER.php"); ?>
Again, all the old CSS works fine, just any new additions to any of the style sheets will not display.
Thanks
<link rel="stylesheet" type="text/css" href="css/Custon_Foundation_Overides.css">
Maybe "Custon_Foundation_Overides.css" is a typo and you meant "Custom_Foundation_Overrides.css" or maybe you have to upload the file with correct letters capitalization.
Sounds like a browser cache issue. A simple way to fix this while maintaining good caching practices would be to pass the file make time as a query var to the file.
<link rel="stylesheet" type="text/css" href="css/foundation.css?ver=<?php echo filemtime('css/foundation.css');?>">
This will generate a string like:
<link rel="stylesheet" type="text/css" href="css/foundation.css?ver=1382564850">
This way when you update the file your browser will think its a new file and cache that, but as long as the file remains unchanged it will have the same name and maintain the browser cache.
For some reason my CSS is only working when inline. I'm somewhat new to web design and not really sure about how to track down why this is occurring. It's not like I can open the console to check for errors, so what kinds of things should I look for? I'm sorry I'm not being more specific, I'm just really not even sure what to do.
Say the url is "www.example.com/testing/3"
The page testing.php would load, call API.php and determine what to do when on page testing.php with vale 3. API.php would then call a function on testing.php to deal with whatever that function tells it to do. So basically it calls out, determines which function to handle the URL, then calls back in.
When I include the CSS in the head of testing.php it works. When I just have a link, it doesn't. All of the files are in the same folder and I'm developing on localhost, no files are admin-restricted: I'm the admin anyway so permission isn't an issue.
//test.css
P.special {
color:green;
border:solid red;
margin-top:85px;
}
Head of testing.php
<link a href="test.css" rel="stylesheet" type="text/css"/>
A function on testing.php
function view_event($event_id){
?>
<p class ="special">
//stuff here
</p>
<?
}
<link a href="test.css" rel="stylesheet" type="text/css"/>
would need to be changed to:
<link a href="/test.css" rel="stylesheet" type="text/css"/>
Using relative URLs will not work when you traverse into other directories. Setting it to an absolute URL with / will allow it to work anywhere on site.
You can check the generated page source in your browser and make sure the CSS link is valid and loads the intended CSS file.
Web Developer Tools built into your browser (or as plugins) are very helpful in debugging html, css and js. Get to know them well.
I used to create a unique header and load it in all my pages like this.
<?php
require_once('include/_header.php');
?>
<div id="main">
<!-- My Page -->
</div>
<?
require_once('include/_footer.php');
?>
In my root folder I have a folder named css where I put all my css stylesheets
in the header I call <link rel="stylesheet" href="css/style.css" type="text/css">.
Now, suppose I have to create a subfolder inside my root and I create a web page into it. When I call my stylesheets from the header, the page doesn't show correctly, because I call the stylesheet in a wrong way. How can I call my stylesheet in a way so that it can always be reachable from any position?
Here is the schema:
css
-style.css
include
-_header.php
-_footer.php
folder
-mypage.php
Use an absolute path:
<link rel="stylesheet" href="/css/style.css" type="text/css">
(Note the slash before the css directory)
Let me offer a way to debug this particular issue and other CSS reference issues in the future. Open up your page and then activate your browser's developer tools. (CTRL+SHIFT+I in Chrome).
Go to the Elements tab. Navigate the DOM until you see the CSS Entry. The URL for the stylesheet will be a clickable hyperlink. Click it. See where the browser navigates you. this should give you an indication as to what the fix is. Maybe you are too deep in the folder structure, maybe you are too shallow. In any case, I solve 99% of my CSS reference issues this way.
You should a base URL in your HTML header
<base href="http://website.com/"/>
Then everything regardless will become as follows..
<link href="css/style.css" rel="stylesheet" type="text/css">
Down the track for your menus you and simply go
Contact
Change your stylesheet href to href="/css/style.css"