Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    May 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Setting Directory Structure in HTML/CSS Files

    I have a website that I am storing under a directory called "Website." I want to put all my images for my Web pages in a subfolder called "Images," all my CSS in a subfolder called "CSS" and all my Javascripts in a subfolder called "Javascripts." Like this:

    Website\*.html
    Website\Images\*.jpg
    Website\CSS\*.css
    Website\Javascript\*.js

    I coded my pages to reflect these paths, but for some reason, my web pages won't load my background image that is specified in a CSS. I would think the path from the CSS would be ..\Images\background.jpg , but that isn't working. The Web pages load images correctly that are specified in the Web page. I'm wondering if something is overriding the path from the CSS to the Image folder?

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,445
    Thanks
    23
    Thanked 630 Times in 629 Posts
    Your css code should be loaded into your html so paths are relative to the html location, in other words background:url(Images/background.jpg) no-repeat;

  • #3
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,778
    Thanks
    6
    Thanked 1,021 Times in 994 Posts
    Sorry, sunfighter, but that’s not correct. CSS should generally be in an external stylesheet, and the file paths inside that file must be relative to the stylesheet location. Opcode had the basic concept alright but I suppose the problem are the backslashes in the file path which should actually be forward slashes.
    Code:
    background-image: url(../Images/background.jpg);

  • #4
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,445
    Thanks
    23
    Thanked 630 Times in 629 Posts
    OK, My bad. I had to check this out and your right. Why did this work for me all these years? I never put my css in a folder if I made it an external link. Bad habit. Learn stuff everyday on this site.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •