Why is background: url(/images/debbie_160x45.png) no-repeat; not working??
My understanding is that in HTML, a forward slash represents the Web Root and therefore whether the page referencing this stylesheet is in the Web Root itself (e.g. “index.php”) or in another sub-directory (e.g. “pages/article_index.php”) the pages should be able to find my background image?!
It the H1 appearing on pages but not the bg image? If the H1 is appearing, then presumably the include is working. There is nothing wrong with the CSS, so something else is amiss. As usual, a link would be helpful.
tbh, I find absolute paths can be a pita so I always use relative paths instead.
You’re using an absolute path in that url, so the actual path you are specifying is the path to your web root directory appended with your absolute path.
Have a look at what your web root path actually is, then append the path in your “url” and see if the image exista at that “full” path. Otherwise consider using relative paths. If using relative paths, the path to a file (image or whatever) needs to be relative to the directory containing the file your css is in.
Like I said, I find relative paths a lot less problematic - but that’s just me
Weird. tba, I find relative paths can be a pita so I always use absolute paths instead. You can set the path and not have to think about it again, no matter what page you are linking from. The only problem can be with PHP includes etc., where a url is not enough. For example, with includes you need something like
<?php include [COLOR="#FF0000"]$_SERVER["DOCUMENT_ROOT"] .[/COLOR] "/components/body_header.inc.php"; ?>
Perhaps that’s needed with require_once too, though PHP ain’t my thing, so I don’t know.
But I suspect DD is working locally, in which case—as you say—the absolute URLs might not actually be pointing to the web root. I gues that’s the other problem with absolute urls, but I don’t work locally much, and when I do, I set up virtual hosts so that the web root locally is the same as remotely.
For me it’s just a personal choice - I just prefer, because I find things work much easier that way, to specify relative paths from the website’s root folder, except for url’s in the css file where they have to be relative to the folder the css file is in.
I’m not sure what you mean by “locally”. I do all my coding on a “local” web server (xampp) and so it is essentially the same as working on the www.
Ralph, this is one time me posting my code won’t help you…
Why?
Because the PITA image is a “background” image, and when I run my index.php this is the source I see…
<body>
<div id="pageWrapper" class="clearfix">
<div id="pageInner">
<!-- BODY HEADER -->
<!-- PAGE HEADER -->
<div id="pageHeader">
<!-- Display Company Logo -->
<h1 id="homePage">
<span></span>Debbie's Company
</h1>
Remember, the image appears as a background image when we style <span>…
As far as Absolute vs Relative, I say it depends on where you are using things.
From what I have learned, RELATIVE paths seem to work much better wuth things like HTML src.
And ABSOLUTE paths seem to work better for PHP includes, especially when the include is being used by different files in different places for things like my Page Header.
Again it boils down to personal preference because you can use either absolute or relative paths in includes and they both work equally well. Just use the type of path you are more comfortable with
The last time I used an absolute path to specify the url in an include(), I think I was still in nappies.
That’s right and is exactly what I said earlier - it boils down to personal preference.
If you look at my previous post you will see the point of trying a relative path in this case, which would have worked if you had not forgotten to assign a stylesheet, was to test if the absolute path from your web root was correct or not.
As it turns out, the relative path would not have worked either because YOU FORGOT TO ASSIGN A STYLESHEET