Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I add link to background image in CSS ? 3

Status
Not open for further replies.

electronicmonkey

Technical User
Feb 19, 2007
45
GB
Hi;
I am having a headache trying to figure this out. If I can, please tell me how . My present background image code :

background:#666666 url("image url") no-repeat right;

 
I mean to add hyperlink to the image so that it goes to another URL when clicked

 
Hi

You can not add any functionality to a background image itself. But you can add it to the element which has the it as background. But certainly not with CSS.

Feherke.
 
My idea is just to give the <body> tag an onclick that will use Javascript to redirect to the page you want. You will have to use .cancelBubble on anything that already has an onclick on it, because it will try to perform both onclick actions.

[monkey][snake] <.
 
Thanks I am not sure these will work for me. The situation is that I have a page element (let's say right column). The right column has an header row which I have assigned a background image through CSS. However I need this header image to be clickable.

 
If the header is a link, you can use display:block making the whole 'block' clickable (technically not the image, but the point is moot).
A working example:
Code:
#nav h3 a {
	[b]display: block;[/b]
	width: 95%;
        background:#666666 url("image url") no-repeat right; }

Greg
"Personally, I am always ready to learn, although I do not always like being taught." - Winston Churchill
 
Thanks; I think I will probably need to introduce a table into the html then; I wanted to avoid that

 
...I think I will probably need to introduce a table into the html then;
Not neccessarily. What html structure/element are you using now for what you are calling your header row?

Greg
"Personally, I am always ready to learn, although I do not always like being taught." - Winston Churchill
 
The situation is that I have a page element (let's say right column). The right column has an header row which I have assigned a background image through CSS. However I need this header image to be clickable.

There are a few ways to go about this.

1. Like traingamer stated above, put an anchor inside the header and make the anchor display:block

Code:
<h3><a href="whereever.com">Header Text</a></h3>

In this code assign the height and width of the anchor with CSS style the font how you want.

Put the background image in the header element, then the entire block of the header will become a link.

2. You can make the anchor itself a psuedo-header.

Code:
<a href="whereever.com">Header Text</a>
In this case the only difference from #1 is that you put the background image on the anchor, since you won't be using a header object.

3. Use javascript to put an onclick on the header object. I'm assuming you don't want this though, since it can be disabled.


[monkey][snake] <.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top