style sheet location

P

petermichaux

Hi,

I want to use a style sheet for several pages. My directory tree is
somthing like this

Level 1: ~/Index.html
Level 2: ~/folder1/page1.html
Level 3: ~/folder1/folder11/page11.html

I want to put the style sheet in level one and then refer to the style
sheet in all of the pages. Is there a way to link the style sheet in
page1.html or page11.html so that it searches it's own folder for the
style sheet and if it doesn't find the style then it searches the next
higher level and then the next higher level above that? I think what
I'm trying to say is I want to "search up the tree".

I'm trying to make it easy to move the pages around from level to level
without having to change "../../" to "../" when I move a page up a
level.

Also I don't want to make hard reference to whatever ~ happens to be.

Thanks,
Peter
 
D

Disco Octopus

Hi,

I want to use a style sheet for several pages. My directory tree is
somthing like this

Level 1: ~/Index.html
Level 2: ~/folder1/page1.html
Level 3: ~/folder1/folder11/page11.html

I want to put the style sheet in level one and then refer to the style
sheet in all of the pages. Is there a way to link the style sheet in
page1.html or page11.html so that it searches it's own folder for the
style sheet and if it doesn't find the style then it searches the next
higher level and then the next higher level above that? I think what
I'm trying to say is I want to "search up the tree".

I'm trying to make it easy to move the pages around from level to level
without having to change "../../" to "../" when I move a page up a
level.

Also I don't want to make hard reference to whatever ~ happens to be.

Thanks,
Peter

you could probably do something like this using your .hteaccess file to
redirect (or rather obtain content from) the
current/parent/grandparent/greeatgrandparent etc.
not sure how you would do this, but it may give you a starting thought.
 
P

petermichaux

The reason I ask is because I want to be able to use my style sheets on
my local copy of my website. Then when I mirror upload to the web
server I want the pages to use the style sheets off the server.

Thanks,
Peter
 
C

Carolyn Marenger

Hi,

I want to use a style sheet for several pages. My directory tree is
somthing like this

Level 1: ~/Index.html
Level 2: ~/folder1/page1.html
Level 3: ~/folder1/folder11/page11.html

I want to put the style sheet in level one and then refer to the style
sheet in all of the pages. Is there a way to link the style sheet in
page1.html or page11.html so that it searches it's own folder for the
style sheet and if it doesn't find the style then it searches the next
higher level and then the next higher level above that? I think what I'm
trying to say is I want to "search up the tree".

I'm trying to make it easy to move the pages around from level to level
without having to change "../../" to "../" when I move a page up a level.

Also I don't want to make hard reference to whatever ~ happens to be.

Thanks,
Peter

'base href' isn't quite what you are looking for, but it might do
what you need.

<head>
<title>base href example</title>
<base href="www.example.com">
<link rel="stylesheet" href="mystyle.css">
</head>
<body>
....
</body>

The downfall is that all your links, not just your css link will then use
the same base directory.

Carolyn
 
K

Kyle Matthews

I'm trying to make it easy to move the pages around from level to level
without having to change "../../" to "../" when I move a page up a
level.

Refer to the document root when you link to the style sheet thus:

<link rel="stylesheet" type="text/css" href="/style.css" />

This will look for the stylesheet in the uppermost folder on your site.
You can move the file containing this line anywhere in your directory
structure and it will always look for it in the same place.

Alternatively you can place your stylesheet(s) in its/their own folder
and refer to it at /styles/style.css.

Kyle
 
D

Disco Octopus

Hi,

I want to use a style sheet for several pages. My directory tree is
somthing like this

Level 1: ~/Index.html
Level 2: ~/folder1/page1.html
Level 3: ~/folder1/folder11/page11.html

I want to put the style sheet in level one and then refer to the style
sheet in all of the pages. Is there a way to link the style sheet in
page1.html or page11.html so that it searches it's own folder for the
style sheet and if it doesn't find the style then it searches the next
higher level and then the next higher level above that? I think what
I'm trying to say is I want to "search up the tree".

I'm trying to make it easy to move the pages around from level to level
without having to change "../../" to "../" when I move a page up a
level.

Also I don't want to make hard reference to whatever ~ happens to be.

Thanks,
Peter

Will it be relative to the location of the current page?
If so, then perhaps do this in every page....

<link rel="stylesheet" type="text/css" href="/style.css" />
<link rel="stylesheet" type="text/css" href="./style.css" />

That way, you will always load the default "/style.css" in the root
location, and all styles referred to in the "./style.css" (if it
exists) will override the ones in "/style.css". If it doesnt exist,
then it simply wont override any default styles.

Now, the question is, will things (users, browsers, log files, etc"
mind if your "./styles.css" file does not exist?

Not really clean, but perhaps a quick workaround???
 
P

petermichaux

Kyle,

I tried this kind of referencing for a image test on my website. It
didn't work.

http://members.shaw.ca/petermichaux/HTMLTest/test5.html

It also won't work on my local copy because the image or style sheet is
not in the top "/" directory. In my local copy the style sheet will be
in something like "/users/peter/Documents/website/".

I want my local copy of the website to use the local copy of the style
sheet. I want the server copy of the website to use the server copy of
the style sheet. And I don't want to change any HTML files before I
mirror upload to the server. Doesn't everybody want to do the same
thing as me??? No way to search up the tree?

Thanks,
Peter
 
N

Nico Schuyt

Kyle Matthews wrote:
I tried this kind of referencing for a image test on my website. It
didn't work.
http://members.shaw.ca/petermichaux/HTMLTest/test5.html
It also won't work on my local copy because the image or style sheet
is not in the top "/" directory. In my local copy the style sheet
will be in something like "/users/peter/Documents/website/".
I want my local copy of the website to use the local copy of the style
sheet. I want the server copy of the website to use the server copy of
the style sheet. And I don't want to change any HTML files before I
mirror upload to the server.
Doesn't everybody want to do the same
thing as me??? No way to search up the tree?

Maybe some PHP can solve it:
if (fileexists("/users/peter/Documents/website/style.css"){
$stylesheet="/users/peter/Documents/website/style.css";
}else{
$stylesheet="http://www...../style.css";
}
<link rel="stylesheet" type="text/css" href<? echo $stylesheet; ?>" />
 
P

petermichaux

NIco,

Thanks for the idea. I thought about this approach but didn't know how
to do it. I will try your suggestion. The only problem would be if a
user viewing my website has a file called
"/users/peter/Documents/website/style.ccs" on their own computer. I
could pick a name that is not likely to occur on someone elses computer
but I thought there could be a better solution other there.

Thanks,
Peter
 
P

petermichaux

I tried the following. It didn't work. I tried your locations of <? and
?> as well. didn't work. Something little is out of place. Never used
php before. here is my file called test7.html

<html>

<head>

<title> HTML Test Page 7 with a little php</title>

<?php
if (fileexists("/users/peter/Documents/website/style.css"){
$stylesheet="/users/peter/Documents/website/style.css";
}else{
$stylesheet="http://members.shaw.ca/petermichaux/style.css";
}
<link rel="stylesheet" type="text/css" href=echo $stylesheet;>
?>
</head>

<body>

<h1>This is Heading 1</h1>
<h2>This is Heading 2</h2>

<p>
This is my test page 6
</p>

<p>
Below is IMG SRC="../HappyFace.jpg"
</p>

<IMG SRC="../HappyFace.jpg">

</body>

</html>
 
R

Rob_W

I tried the following. It didn't work. I tried your locations of <? and
?> as well. didn't work. Something little is out of place. Never used
php before. here is my file called test7.html
[page-coding snipped]

1. When using PHP-code you can't use .html, you have to use .php extension.
2. Are you all set up to run PHP on your local server? You installed PHP
and/or Apache?

RW
 
P

petermichaux

Rob,

Thanks. I turned on Apache on my Mac and installed PHP. I have a PHP
version of Hello World running locally. But I uploaded it to my ISP's
server and it doesn't run. Arg! Maybe residental accounts are not
allowed to use PHP. I'll have to phone them. Hello World doesn't work
here:

http://members.shaw.ca/petermichaux/HTMLTest/test8.php

Thanks for your help, though. If I'm doing something obviously wrong
please let me know.

Peter
 
B

Beauregard T. Shagnasty

K

kchayka

They will not let me or any of their customers use php. They claim
there is a security issue.

I would guess the security issue has little to do with php. More like
their servers are the real problem. According to Netcraft,

http://members.shaw.ca was running NetCache on NT4/Windows 98

NT4/W98? That would give me cause for concern right there.
 
T

Toby Inkster

petermichaux said:
It also won't work on my local copy because the image or style sheet is
not in the top "/" directory. In my local copy the style sheet will be
in something like "/users/peter/Documents/website/".

<link rel="stylesheet" type="text/css"
href="/style.css">
<link rel="stylesheet" type="text/css"
href="file:///users/peter/Documents/website/style.css">

Depending on whether you are testing the website locally or on the server,
one of the URLs will not be found, but as they both point to the same file
it doesn't matter.

That said, I don't really understand the need for local testing. Simply
create testing.yourdomain.com, test your stuff there and copy across to
the real domain when you're done.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,072
Latest member
trafficcone

Latest Threads

Top