0

I am facing trouble in css relative path.

I have used background property in css file and mention relative url path of an image in it.But that image act in my HTML file as an absolute path.I want to know that how we can make relative path for both CSS and HTML file using CSS property only.

Nikolay Kostov
  • 16,433
  • 23
  • 85
  • 123
Ashish
  • 174
  • 2
  • 13
  • Can you provide some code? It's not clear what your problem is. – Lance Jun 24 '15 at 01:54
  • imagine that your folder structure is like that [ROOT] => index.html, CSS, JS, IMGS. That way your html document lies in the root and that root contains subfolders named css, js and imgs. if you want to declare an image path out of your css styleshett it would be ('../imgs/test.jpg'); double dot jumps one folder backwards if you want to call it directly in the html document you have to use one dot ('./imgs/test.jpg'); – noa-dev Jun 24 '15 at 07:28
  • may be this link is useful [http://stackoverflow.com/questions/5815452/how-to-use-relative-absolute-paths-in-css-urls][1] [1]: http://stackoverflow.com/questions/5815452/how-to-use-relative-absolute-paths-in-css-urls – yojna Jun 24 '15 at 08:04
  • @Lance... I am using the following property in css => background:url('../../images/image.jpg'); .I know its relative path.But in my html document where I am accessing this css file acting as a absolute url path of an image .For SEO perspective,I have to change it. – Ashish Jun 25 '15 at 00:03

1 Answers1

0

You should be able to put a / at the beginning of your path and have it be relative to the top of your web root. It would look something like this:

background:url(/images/stuff/myimg.png);
nixkuroi
  • 2,259
  • 1
  • 19
  • 25
  • @nixkuroi...I used same url in my css file.But in included css file it acting as a absolute path. – Ashish Jun 25 '15 at 00:05
  • style.cssfjskdjfksd

    In stylesheet.I have included :- background:url(/images/stuff/myimg.png); Image is displaying in html page.But path of image is acting as an absolute path while I checking in my SEO plugin.Plugin says you have defined absolute path

    – Ashish Jun 30 '15 at 20:36
  • Can you give me the paths of your html file and your css file and your images? That might help me see why your plugin is saying it's an absolute path. I think when you use a beginning slash, it gets interpreted from the browser as an absolute path because it makes the path relative to the root. – nixkuroi Jul 01 '15 at 21:06