The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Where to put css files?, Do css files only work in the html directory?
km4hr
post Aug 3 2011, 03:50 PM
Post #1





Group: Members
Posts: 4
Joined: 3-August 11
Member No.: 15,074



Descriptions of <link href=/dirname/filename> seem to indicate that css files can be put in any directory on the server. But mine only work when they are in the "html" directory. I've tried specifying other directory locations every way possible using "href=" but nothing works unless I put my css file in the "html" directory. What are web sites like this talking about when they refer to "relative" ulr's? What does relative mean? Relative to what?

I'm using Apache on Linux. My html directory is "/var/www/html". My css files work fine in this directory but nowhere else. Is there any way I can put them with my other project files? I want to put css files in "/var/www/cssfiles" directory for example. Is that possible?

thanks
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Aug 3 2011, 04:00 PM
Post #2


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,716
Joined: 9-August 06
Member No.: 6



If nothing else is said, relative means relative to the document the URL is in. But there are also root relative URLs. See http://htmlhelp.com/faq/html/basics.html#relative-url .

Yes, you can put your CSS files anywhere as long as they are accessible from the web. Maybe /var/www/html is your document root, i.e. the directory that is accessible from the web? You can't place files that browsers should read above the document root in the file structure.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Darin McGrew
post Aug 3 2011, 06:57 PM
Post #3


WDG Member
********

Group: Root Admin
Posts: 8,365
Joined: 4-August 06
From: Mountain View, CA
Member No.: 3



Another possible issue is that URLs in the CSS style sheets are evaluated relative to the CSS style sheets. So if you move just the CSS file, then the URLs in the CSS file can be wrong.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
km4hr
post Aug 3 2011, 11:15 PM
Post #4





Group: Members
Posts: 4
Joined: 3-August 11
Member No.: 15,074



QUOTE(pandy @ Aug 3 2011, 05:00 PM) *

If nothing else is said, relative means relative to the document the URL is in. But there are also root relative URLs. See http://htmlhelp.com/faq/html/basics.html#relative-url .

Yes, you can put your CSS files anywhere as long as they are accessible from the web. Maybe /var/www/html is your document root, i.e. the directory that is accessible from the web? You can't place files that browsers should read above the document root in the file structure.


The web site we are using as a reference says the following
============================================================================
The URL of the linked document.
Possible values:

* An absolute URL - points to another web site (like href="http://www.example.com/theme.css")
* A relative URL - points to a file within a web site (like href="/themes/theme.css")
==============================================================================

From what I can determine experimentally the file "theme.css" described in the above "absolute URL" statement must be located in the document root directory. In my case that directory is "/var/www/html". (I hope I'm saying that correctly. I'm not absolutely sure what "document root" means.)

In the above statement referring to "relative URL's" the "theme" directory apparently must be a subdirectory of the document root directory. My trial and error results indicate it can't be anywhere else. I wonder why am I having use trial and error anyway? Why don't they just say that? Maybe it's assumed that readers know a lot about how web servers work.

The missing piece in the reference's otherwise excellent explanation is that "href=" only works when css files are either in the document root directory or one of it's subdirectories. I just don't understand the logic of having separate css files from related project files.

What I want to do is put my css file in the same directory with it's associated project files. But again the "href=" restricts location of css files to "/var/www/html" or one of it's subdirectories on my server. So "href=" is not nearly as flexible as a novice programmer (me) is led to believe.

My web page is generated by a cgi script. The script is located in "/var/www/cgi-bin". I want to put my css file in the same directory as the cgi file to keep things organized and to help other support programmers find all related files.

Disclaimer: I'm a beginner. I really don't know what I'm talking about, in case someone didn't notice that already.

thanks!

User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Aug 4 2011, 04:00 AM
Post #5


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,716
Joined: 9-August 06
Member No.: 6



QUOTE(km4hr @ Aug 4 2011, 06:15 AM) *

The web site we are using as a reference says the following
============================================================================
The URL of the linked document.
Possible values:

* An absolute URL - points to another web site (like href="http://www.example.com/theme.css")
* A relative URL - points to a file within a web site (like href="/themes/theme.css")
==============================================================================

From what I can determine experimentally the file "theme.css" described in the above "absolute URL" statement must be located in the document root directory.


Correct.



QUOTE
In my case that directory is "/var/www/html". (I hope I'm saying that correctly. I'm not absolutely sure what "document root" means.)


If that is where you have your main index.html, it is. That is, the directory you go to with a browser when you enter your domain name, http://example.com.

I'm confused, have you set this up on your own machine? Because /var/www/html can't be a path for an account at a share host. If so, the document root is in your Apache configuration. It's necessary to have one to protect the rest of the machine's file system from the access from the web.

At a host you typically, but not always, get access to one directory above the document root. That is, when you FTP to your account you land in a directory that can't be accessed from the web. There are usually several precreated folders, one of them being the document root. It could be called 'www', 'httpdocs' or just about anything, but you usually understand what it is from the name.



QUOTE
In the above statement referring to "relative URL's" the "theme" directory apparently must be a subdirectory of the document root directory.

Yes.


QUOTE
My trial and error results indicate it can't be anywhere else. I wonder why am I having use trial and error anyway? Why don't they just say that? Maybe it's assumed that readers know a lot about how web servers work.


Who are they? Are you hosted after all?

QUOTE

The missing piece in the reference's otherwise excellent explanation is that "href=" only works when css files are either in the document root directory or one of it's subdirectories. I just don't understand the logic of having separate css files from related project files.


What are the project files? Are they above the document root?

QUOTE
What I want to do is put my css file in the same directory with it's associated project files. But again the "href=" restricts location of css files to "/var/www/html" or one of it's subdirectories on my server. So "href=" is not nearly as flexible as a novice programmer (me) is led to believe.


It isn't about href. It is about server configuration and integrety of the file system. I don't know if you are using Windows normally, but if you are think of it as sharing a folder. You share a certain folder and everything within it. In the same way you give web access to a certain folder and all its sub folders, but nothing ABOVE that folder. You don't want people walking all over your hard drive.


QUOTE
My web page is generated by a cgi script. The script is located in "/var/www/cgi-bin". I want to put my css file in the same directory as the cgi file to keep things organized and to help other support programmers find all related files.


If they (who?) force you to use a special folder for Perl scripts, the best organization probably is to use it for Perl scripts alone.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
km4hr
post Aug 4 2011, 12:16 PM
Post #6





Group: Members
Posts: 4
Joined: 3-August 11
Member No.: 15,074



Thank you Pandy.

QUOTE(pandy @ Aug 4 2011, 05:00 AM) *

QUOTE(km4hr @ Aug 4 2011, 06:15 AM) *

The web site we are using as a reference says the following
============================================================================
The URL of the linked document.
Possible values:

* An absolute URL - points to another web site (like href="http://www.example.com/theme.css")
* A relative URL - points to a file within a web site (like href="/themes/theme.css")
==============================================================================

From what I can determine experimentally the file "theme.css" described in the above "absolute URL" statement must be located in the document root directory.


Correct.

QUOTE
In my case that directory is "/var/www/html". (I hope I'm saying that correctly. I'm not absolutely sure what "document root" means.)


If that is where you have your main index.html, it is. That is, the directory you go to with a browser when you enter your domain name, http://example.com.

I'm confused, have you set this up on your own machine? Because /var/www/html can't be a path for an account at a share host. If so, the document root is in your Apache configuration. It's necessary to have one to protect the rest of the machine's file system from the access from the web.

>> Yes, the server is my own machine. It's sitting next to my desk. It is on a local network, not on the internet. Security is not a major concern. I'd turn most security features off if I knew how. I installed Apache myself. I have root access to the server.

At a host you typically, but not always, get access to one directory above the document root. That is, when you FTP to your account you land in a directory that can't be accessed from the web. There are usually several precreated folders, one of them being the document root. It could be called 'www', 'httpdocs' or just about anything, but you usually understand what it is from the name.


QUOTE
In the above statement referring to "relative URL's" the "theme" directory apparently must be a subdirectory of the document root directory.

Yes.


QUOTE
My trial and error results indicate it can't be anywhere else. I wonder why am I having use trial and error anyway? Why don't they just say that? Maybe it's assumed that readers know a lot about how web servers work.


Who are they? Are you hosted after all?

>> "They" are the people who write html documentation, like that shown at the beginning of this message. It would have saved me hours if they just stated in the explanation of "href=" that document root (/var/www/html) will be appended (prepended?) to whatever comes after the "=" sign. For example if they had said that "href="/themes/theme.css" becomes "<document root>/themes/theme.css" it would be clear what directory the css file must be placed in on the server.

QUOTE

The missing piece in the reference's otherwise excellent explanation is that "href=" only works when css files are either in the document root directory or one of it's subdirectories. I just don't understand the logic of having separate css files from related project files.


What are the project files? Are they above the document root?

>> Ideally I'd put all files related to a project in one directory (and subdirectories). I'm talking about files like C source files, make files, css files, image files, and whatever other files are part of a project (application). They way they would could be backed up easily, and other programmers wouldn't have to guess where the pieces are.

QUOTE
What I want to do is put my css file in the same directory with it's associated project files. But again the "href=" restricts location of css files to "/var/www/html" or one of it's subdirectories on my server. So "href=" is not nearly as flexible as a novice programmer (me) is led to believe.


It isn't about href. It is about server configuration and integrety of the file system. I don't know if you are using Windows normally, but if you are think of it as sharing a folder. You share a certain folder and everything within it. In the same way you give web access to a certain folder and all its sub folders, but nothing ABOVE that folder. You don't want people walking all over your hard drive.

>> I configured the web server myself, at least as well as I know how at this point. It's a challenge for a non-web developer. My main job is Mechanical Engineer but due to cutbacks I wear a number of hats. I am knowlegable in C programming however. I am using this knowledge to create cgi scripts. It actually works pretty well. It's just a bit overwhelming to do computer admin, web admin, and developer.


QUOTE
My web page is generated by a cgi script. The script is located in "/var/www/cgi-bin". I want to put my css file in the same directory as the cgi file to keep things organized and to help other support programmers find all related files.


If they (who?) force you to use a special folder for Perl scripts, the best organization probably is to use it for Perl scripts alone.

User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Aug 4 2011, 12:30 PM
Post #7


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,716
Joined: 9-August 06
Member No.: 6



OK. Then open httpd.conf and search for a line beginning with DocumentRoot. Change the path you find there to what you want it to be.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
km4hr
post Aug 4 2011, 02:07 PM
Post #8





Group: Members
Posts: 4
Joined: 3-August 11
Member No.: 15,074



QUOTE(pandy @ Aug 4 2011, 01:30 PM) *

OK. Then open httpd.conf and search for a line beginning with DocumentRoot. Change the path you find there to what you want it to be.


I think I'll leave the document root specification alone in httpd.conf. I want to keep the server configuration as standard as possible to minimize confusion for others. I'd like to do things the way the Apache designers intended, if I can figure out what that is.

I do wonder what happens when there are multiple users on a web server. Are all users required to put their html files, css files, cgi scripts in the same directories? That seems messy. Maybe I'll explore public_html(?) if that need ever arises. ... Or maybe that's a way to put all my files under one directory without re-configuring the web server. I'll check that out.

So many questions, so little time!

Thanks again.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Aug 4 2011, 02:14 PM
Post #9


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,716
Joined: 9-August 06
Member No.: 6



The people who wrote Apache intended for you to specify some things, a whole lot of them actually, among them the document root. There is no standard.

Anyway, at lest take a look so you know for sure where the document root is and don't have to guess.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 28th March 2024 - 06:58 PM