473,385 Members | 1,919 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

background-image problem while using CSS for aspx page

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.
Nov 18 '05 #1
7 5102
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

"Nilesh" <dh*******@hotmail.com> wrote in message
news:ae**************************@posting.google.c om...
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.

Nov 18 '05 #2
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" <dh*******@hotmail.com> wrote in message
news:ae**************************@posting.google.c om...
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.

Nov 18 '05 #3
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" <de*******@hotmail.com> wrote in message
news:uk**************@TK2MSFTNGP09.phx.gbl...
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" <dh*******@hotmail.com> wrote in message
news:ae**************************@posting.google.c om...
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.


Nov 18 '05 #4
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" <ji******@infinityinfo.com> wrote in message
news:eb**************@TK2MSFTNGP12.phx.gbl...
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" <de*******@hotmail.com> wrote in message
news:uk**************@TK2MSFTNGP09.phx.gbl...
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" <dh*******@hotmail.com> wrote in message
news:ae**************************@posting.google.c om...
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.



Nov 18 '05 #5
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" <dh*******@hotmail.com> wrote in messag
news:ae**************************@posting.google.c om..
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
regards

Nilesh Dhakras


Nov 18 '05 #6
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" <de*******@hotmail.com> wrote in message news:<#j**************@tk2msftngp13.phx.gbl>...
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" <ji******@infinityinfo.com> wrote in message
news:eb**************@TK2MSFTNGP12.phx.gbl...
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" <de*******@hotmail.com> wrote in message
news:uk**************@TK2MSFTNGP09.phx.gbl...
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" <dh*******@hotmail.com> wrote in message
news:ae**************************@posting.google.c om...
> 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.


Nov 18 '05 #7
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" <dh*******@hotmail.com> wrote in message
news:ae**************************@posting.google.c om...
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" <de*******@hotmail.com> wrote in message

news:<#j**************@tk2msftngp13.phx.gbl>...
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" <ji******@infinityinfo.com> wrote in message
news:eb**************@TK2MSFTNGP12.phx.gbl...
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" <de*******@hotmail.com> wrote in message
news:uk**************@TK2MSFTNGP09.phx.gbl...
> 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" <dh*******@hotmail.com> wrote in message
> news:ae**************************@posting.google.c om...
> > 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.
>
>

Nov 18 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Paul Schnitter | last post by:
Update: My custom control is based on the article "Creating Visual Basic .NET controls from scratch" in "Adventures in .NET" on MSDN. It is designed to be a replacement for the VB6 shape...
12
by: Stanimir Stamenkov | last post by:
Here are two cases regarding inline-level elements' line-height, padding and background, which I doesn't understand: <div style="background: black; color: white; line-height: 1.5">...
7
by: ryan.fairchild | last post by:
Ok I basically am creating a container for a bunch of other <div> tags. But I want to make four jpegs/gif/whatever that goes in each corner so they look rounded. I thought this is how I would do...
16
by: J. B. Moreno | last post by:
I read the faq, and it mentions that IE 4 on windows requires setting a printing option to allow background colors to be printed. Things change, life goes on, other browsers come into...
1
by: laredotornado | last post by:
Hello, I was wondering if there is any cross-browser CSS way to specify that I want the background color of a readonly input text field to be the same as its parent row. Right now, I have ...
2
by: bissatch | last post by:
Hi, I am running a w3c CSS validation check on a site in development. I have many errors saying that my CSS is not valid because I have not defined the background-color but instead left it...
7
by: Guliver | last post by:
Hello. I'm configuring the apearence of my forum and I have a question for anyone who can help me. I have a backgroud picture and I would like it to be visible but I'm trying to mantain a...
11
by: Gérard Talbot | last post by:
Hello, <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <title></title> <style type="text/css"> body {background-color: white; color: black;}...
19
by: david.karr | last post by:
If in my CSS I set the "background-color" property on the "body" element, it only covers the background of the elements defined in the body, up to the current width and height of the page. However,...
4
by: yawnmoth | last post by:
I'm trying to write a script whereby the body background is changed to back (from white) when the mouse button is held down and kept held down. When you lift it up, I'd like it to change back to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.