background-image problem while using CSS for aspx page

N

Nilesh

I am using background-image attribute in a CSS file and linking the
CSS file to aspx page. But strangly, background-image attribute is not
working for relative URL.

e.g. If I apply following css
..navbar-background {
background-image: url(images/menubar.gif);
}

the image is not appearing on the page. It seems that IE is picking
the image path relative to aspx file (instead of CSS file!)

If i change the CSS to
..navbar-background {
background-image: url(http:\\myserver\cp\images\menubar.gif);
}
then it's working.
What is the problem here?? Can someone please explain?
[Note: I am using IE6]

regards,
Nilesh Dhakras.
 
A

Ashish M Bhonkiya

Hi Nilesh,

try making the changes as follows. its the problem with the relative path i
assume that your images folder is in the root directory.

e.g. If I apply following css
..navbar-background {
background-image: url(~/images/menubar.gif);
}

HTH
Regards
Ashsih M Bhonkiya
 
M

Martin Dechev

Hi, Nilesh Dhakras,

The paths should be relative to the .css file. Are you sure you are not
seeing a cached version of the .css (the one cached in the browser)? Try to
hit Ctrl+F5 to force the browser to request everything.

Also, make sure you don't have any error in the css style - if there is an
error you will not be shown any error messages, simply there will be no
styles applied to the control.

Hope this helps
Martin
 
J

Jiho Han

It's been my experience that the url property is always relative to the page
not the stylesheet.
I've checked both MSDN and W3C spec but they don't seem to discuss about the
url attribute in detail.

Jiho

Martin Dechev said:
Hi, Nilesh Dhakras,

The paths should be relative to the .css file. Are you sure you are not
seeing a cached version of the .css (the one cached in the browser)? Try to
hit Ctrl+F5 to force the browser to request everything.

Also, make sure you don't have any error in the css style - if there is an
error you will not be shown any error messages, simply there will be no
styles applied to the control.

Hope this helps
Martin
Nilesh said:
I am using background-image attribute in a CSS file and linking the
CSS file to aspx page. But strangly, background-image attribute is not
working for relative URL.

e.g. If I apply following css
.navbar-background {
background-image: url(images/menubar.gif);
}

the image is not appearing on the page. It seems that IE is picking
the image path relative to aspx file (instead of CSS file!)

If i change the CSS to
.navbar-background {
background-image: url(http:\\myserver\cp\images\menubar.gif);
}
then it's working.
What is the problem here?? Can someone please explain?
[Note: I am using IE6]

regards,
Nilesh Dhakras.
 
M

Martin Dechev

Well, it's mentioned in the CSS1 specifications:

http://www.w3.org/TR/REC-CSS1.html#url

Quote:
Partial URLs are interpreted relative to the source of the style sheet, not
relative to the document

Greetings
Martin
Jiho Han said:
It's been my experience that the url property is always relative to the page
not the stylesheet.
I've checked both MSDN and W3C spec but they don't seem to discuss about the
url attribute in detail.

Jiho

Martin Dechev said:
Hi, Nilesh Dhakras,

The paths should be relative to the .css file. Are you sure you are not
seeing a cached version of the .css (the one cached in the browser)? Try to
hit Ctrl+F5 to force the browser to request everything.

Also, make sure you don't have any error in the css style - if there is an
error you will not be shown any error messages, simply there will be no
styles applied to the control.

Hope this helps
Martin
Nilesh said:
I am using background-image attribute in a CSS file and linking the
CSS file to aspx page. But strangly, background-image attribute is not
working for relative URL.

e.g. If I apply following css
.navbar-background {
background-image: url(images/menubar.gif);
}

the image is not appearing on the page. It seems that IE is picking
the image path relative to aspx file (instead of CSS file!)

If i change the CSS to
.navbar-background {
background-image: url(http:\\myserver\cp\images\menubar.gif);
}
then it's working.
What is the problem here?? Can someone please explain?
[Note: I am using IE6]

regards,
Nilesh Dhakras.
 
G

Guest

Hi Nilesh

I am sorry to provide this incorrect information in my last reply

actually the the paths should be relative to the .css file. and thats what the specifications says

"Well, it's mentioned in the CSS1 specifications
http://www.w3.org/TR/REC-CSS1.html#url

----- Ashish M Bhonkiya wrote: ----

Hi Nilesh

try making the changes as follows. its the problem with the relative path
assume that your images folder is in the root directory

e.g. If I apply following cs
..navbar-background
background-image: url(~/images/menubar.gif)


HT
Regard
Ashsih M Bhonkiy

Nilesh said:
I am using background-image attribute in a CSS file and linking th
CSS file to aspx page. But strangly, background-image attribute is no
working for relative URL
e.g. If I apply following cs
.navbar-background
background-image: url(images/menubar.gif)
the image is not appearing on the page. It seems that IE is pickin
the image path relative to aspx file (instead of CSS file!
If i change the CSS t
.navbar-background
background-image: url(http:\\myserver\cp\images\menubar.gif)

then it's working
What is the problem here?? Can someone please explain
[Note: I am using IE6
Nilesh Dhakras
 
N

Nilesh

Hi Martin,

Thanks a lot for your inputs. But I am really facing strange behavior.

I have a base CSS which is having this class
..navbar-background {
background-image: url(images/menubar.gif);
}
The base CSS is working just as expected (and as you explained). The
images are getting picted relative to the CSS file's directory (and
not the page's directory).

But when I create another custom CSS, and override this class in that
CSS, then the problem comes. My custom CSS has exactly same class but
with diff path (as it's placed in a diff directory than the base CSS).
In the page's <HEAD> section, I am mentioning the custion CSS after
the base CSS (to override). But images are not getting picked.

Does background-image attribute have any problem with such
overriding??

Thanks a lot,
Nilesh Dhakras




Martin Dechev said:
Well, it's mentioned in the CSS1 specifications:

http://www.w3.org/TR/REC-CSS1.html#url

Quote:
Partial URLs are interpreted relative to the source of the style sheet, not
relative to the document

Greetings
Martin
Jiho Han said:
It's been my experience that the url property is always relative to the page
not the stylesheet.
I've checked both MSDN and W3C spec but they don't seem to discuss about the
url attribute in detail.

Jiho

Martin Dechev said:
Hi, Nilesh Dhakras,

The paths should be relative to the .css file. Are you sure you are not
seeing a cached version of the .css (the one cached in the browser)? Try to
hit Ctrl+F5 to force the browser to request everything.

Also, make sure you don't have any error in the css style - if there is an
error you will not be shown any error messages, simply there will be no
styles applied to the control.

Hope this helps
Martin
I am using background-image attribute in a CSS file and linking the
CSS file to aspx page. But strangly, background-image attribute is not
working for relative URL.

e.g. If I apply following css
.navbar-background {
background-image: url(images/menubar.gif);
}

the image is not appearing on the page. It seems that IE is picking
the image path relative to aspx file (instead of CSS file!)

If i change the CSS to
.navbar-background {
background-image: url(http:\\myserver\cp\images\menubar.gif);
}
then it's working.
What is the problem here?? Can someone please explain?
[Note: I am using IE6]

regards,
Nilesh Dhakras.
 
M

Martin Dechev

Hi, Nilesh,

You can import the "base" stylesheet in the "custom" like this:

@import url(../styles/base.css);

and then you will be guaranteed to override the class definitions of the
"base" css.

Another thing you can try is to set the background-image as "! important" in
the "custom" css:

..navbar-background {
background-image: url(images/menubar.gif) ! important;
}

but I haven't try this myself. The first method is the official
recommendation for overriding.

Hope this helps
Martin
Nilesh said:
Hi Martin,

Thanks a lot for your inputs. But I am really facing strange behavior.

I have a base CSS which is having this class
.navbar-background {
background-image: url(images/menubar.gif);
}
The base CSS is working just as expected (and as you explained). The
images are getting picted relative to the CSS file's directory (and
not the page's directory).

But when I create another custom CSS, and override this class in that
CSS, then the problem comes. My custom CSS has exactly same class but
with diff path (as it's placed in a diff directory than the base CSS).
In the page's <HEAD> section, I am mentioning the custion CSS after
the base CSS (to override). But images are not getting picked.

Does background-image attribute have any problem with such
overriding??

Thanks a lot,
Nilesh Dhakras




"Martin Dechev" <[email protected]> wrote in message
Well, it's mentioned in the CSS1 specifications:

http://www.w3.org/TR/REC-CSS1.html#url

Quote:
Partial URLs are interpreted relative to the source of the style sheet, not
relative to the document

Greetings
Martin
Jiho Han said:
It's been my experience that the url property is always relative to
the
page
not the stylesheet.
I've checked both MSDN and W3C spec but they don't seem to discuss
about
the
url attribute in detail.

Jiho

Hi, Nilesh Dhakras,

The paths should be relative to the .css file. Are you sure you are not
seeing a cached version of the .css (the one cached in the browser)?
Try
to
hit Ctrl+F5 to force the browser to request everything.

Also, make sure you don't have any error in the css style - if there
is
an
error you will not be shown any error messages, simply there will be no
styles applied to the control.

Hope this helps
Martin
I am using background-image attribute in a CSS file and linking the
CSS file to aspx page. But strangly, background-image attribute is not
working for relative URL.

e.g. If I apply following css
.navbar-background {
background-image: url(images/menubar.gif);
}

the image is not appearing on the page. It seems that IE is picking
the image path relative to aspx file (instead of CSS file!)

If i change the CSS to
.navbar-background {
background-image: url(http:\\myserver\cp\images\menubar.gif);
}
then it's working.
What is the problem here?? Can someone please explain?
[Note: I am using IE6]

regards,
Nilesh Dhakras.
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top