I recently changed my index.html file to index.php and now new styles are not taking effect. When I try to alter the already existing styles, nothing happens until I change back to index.html. A link to my css file looks like this <link rel="stylesheet" href="css/style.css">
Related
My folders are here:
In my header.php there is this code:
<link rel="stylesheet" href="style.css">
In the index.php i can include like this:
include('header.php')
I can reach style.css there is no problem.
But, in the product/product.php
include('../header.php')
I can not reach style.css
I can reach the header.php but i can not reach style.css. Because in the header.php, this include code seems that style.css is in the product/style.css, but my style.css is in home folder. How can i reach? Can u help me?
The solution is simple the browsers try to request the file relative to the current directory, so just need to add / in the begging of the HREF to make sure you are referring to a file that is in the root.
Solution:
<link rel="stylesheet" href="/style.css">
So I have a webpage where I use the same header/footer for every page:
<?php include 'header.php?>
In header link to css looks like this:
<link rel="stylesheet" type="text/css" href="styles.css">
they both are in the same folder.
Problem:
When I try to load page in another folder (products/page.php) - the assets wont load properly. I put a link to header like this:
<?php include '../header.php' ?>
header and footer loads properly but the assets defined in them do not.
How can I fix the paths so I would not need to copy same files to every folder.
Sorry for noob question :)
A pssible solution is to use absolute paths:
<link rel="stylesheet" type="text/css" href="/styles.css">
This way your assets are indepent to your phps structure.
I have looked over the code and cant seem to see where the link between the two files is failing. My index page uses the exact same code to link the files and it works fine. When I add the styling in the header of the php/html file it works but otherwise nothing happens.
The reference that you have for the stylesheet is relative to the url of the page you're on.
For example, this:
<link rel="stylesheet" type="text/css" href="style.css">
... says that the stylesheet is at the same path that the page is on. So if the url in the address bar is https://somewebsite/admin/index.php then that page will try to load the stylesheet at https://somewebsite/admin/style.css. If the url is https://somewebsite/index.php then the page will try to load the stylesheet at https://somewebsite/style.css.
If the stylesheet resides at the root of the site then your link tag should look like this:
<link rel="stylesheet" type="text/css" href="/style.css">
This will make your page look for the stylesheet at https://somewebsite/style.css regardless of what the path of the url says.
You should make the right path, right into your css file at
Example:
<link href="assets/css/blabla.css" rel="stylesheet">
I'm building a PHP based site with this directory structure
index.php
css
style.css
bootstrap.css
includes
header.php
footer.php
bikes
road.php
mountain.php
The Problem
So I'm working on road.php and I obviously need to be able to link to both style.css and bootstrap.css, but when I declare at the start of road.php to include the header.php and footer.php it is like as if it cannot find the stylesheets and the site reverts back to the default 1990s look.
I have also found that any form of link on the page loads a 404. I'm only just starting out with PHP because I need some more power in my sites, but I just can't seem to get my head around the super basic things.
I just don't know what to do and I'm finding myself turning my back on the whole PHP language.
Thanking you in advance,
Stu :)
I can't be certain without seeing the actual content of header.php (in perticular the part where you import the stylesheets), but it sounds like you are using a relative path to your stylesheets. Something like <link rel="stylesheet" type="text/css" href="css/style.css" media="screen" />. This works fine for index.php, but since the other pages are inside the subfolder bikes, they will be looking for the CSS files in yoursite.com/bikes/css.
The solution is to provide an absolute path. Something like this:
<link rel="stylesheet" type="text/css" href="http://yoursite.com/css/style.css" media="screen" />
This way, it doesn't matter if the page is inside a subfolder (or a subfolder of a subfolder) - it will allways look for the CSS file in the right location.
If you are using multiple domain names, or for some other reason you cannot hardcode the domain name, you can prepend a slash (/) to the path as well:
<link rel="stylesheet" type="text/css" href="/css/style.css" media="screen" />
This path is relative to the root of the website, not to the current directory.
I have index.php which uses its own style.css.
I'm including helloworld.php which uses style2.css and JavaScript (it's an image gallery).
When I include helloworld.php on index.php, style2.css gets completely ignored and seemingly not loaded at all. And when I copy the contents of style2.css into style.css, I get the same results - nothing from the included file gets styled properly.
I'm a little bit new at this - is this even possible?
Are you including the link to the other style sheet in your headers on idex.php? Try this.
examples (place inside open / closing tags)
<link rel="stylesheet" type="text/css" href="path/to/style1.css">
<link rel="stylesheet" type="text/css" href="path/to/style2.css">