Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

having background image be a link to another site

Featured Replies

Hi guys. :hi: I have a site where i want one part of my site that is in a div container with a background image to be a link that when it's clicked it goes to my goldstein media site.

 

It pretty much looks like this

 

<div id="rightHeader">&nbsp</div>

 

now in the CSS it looks like this

 

#rightHeader {
   width:191px;
   height:168px;
   float:left;
   background-image:url(../images/main/otdalt_03.jpg);
}

 

now I want when the person clicks that empty div that's not really empty it goes to my site. is there a way to make a <div> hot?

 

Please let me know 8)

 

Thanks! :flm7::drinks:

Hi Seth

 

I may be being dippy (I'm no CSS expert, but I am awake so you're stuck until the others wake up!)

Can't you just put an image surrounded by an anchor tag with the link in it? The anchor and image can then be floated any way you want.

 

Assuming a parent container of #header you have:

 

<div id="header">

blah

blah

blah

<a href="htttp://...."><img src="../images/main/otdalt_03.jpg" /></a>

</div>

 

Or am I missing something?

:D

You can just put the <a> tags arround your div

 

<a href"="http://mysite.com">
   <div id="rightHeader">
   </div>
</a>

 

Haven't checked if HTML Validator will complain though :pp

@rdjejong A block element nested inside an inline element? I'm sure the validator will throw a wobbler!

 

@Seth Definitely try to do what wizely suggested. If that isn't practical for you, you could create a 'false' link over the background image.

Define your header as position:relative;

Then have a link inside the header positioned absolutely.

HTML

<div id="header">
<a id="myfalselink" href="mypage.html" title="go to my page">My Page</a>
</div>

#header {
position:relative;
}
#header a#myfalselink {
position:absolute;
display:block;
height: the height of your header;
width: the width of the background image you want to 'cover';
top:0; /*position it at the top of the header*/
right:0; /*position it at the right of your header*/
text-indent:-5000px; /*make the anchor text disappear*/
}

  • Author
Hi Seth

 

I may be being dippy (I'm no CSS expert, but I am awake so you're stuck until the others wake up!)

Can't you just put an image surrounded by an anchor tag with the link in it? The anchor and image can then be floated any way you want.

 

Assuming a parent container of #header you have:

 

<div id="header">

blah

blah

blah

<a href="htttp://...."><img src="../images/main/otdalt_03.jpg" /></a>

</div>

 

Or am I missing something?

:D

 

Thanks guys for all your help. :hi:

 

Wizely, the main reason why I don't want to make a graphic and put an anchor on it is that this site has possibly 60 pages and everything I have to make a flipping stuctural change it takes me a god awful amount of time. I was hoping there was a way where all I had to do was mess with the css. But I guess that's not so. :unknw: Now I understand why PHP is a good thing to know because you can separate your header and footer into it's own document and just call it up when you need it. I wish there were a way to do this in CSS. Hmmmm, maybe CSS 3.

 

Thanks guys! 8)

The code you are/were looking for is:

 

take out the space:

 

<div id="rightHeader"><a href="#" title=""></a></div>

 

now the CSS:

 

#rightHeader{
width:191px;
height:168px;
float:left;
}

#rightHeader a, #rightHeader a:link, #rightHeader a:visited, #rightHeader a:hover, #rightHeader a:active{
width:100%;
height:100%;
display:block;
outline:none;
background-image:url(../images/main/otdalt_03.jpg);
} 

 

That does the trick. If you want the image to change on rollover then just copy the last block of CSS but just leave the "#rightHeader a:hover" as the identifier and change the image (or shift the image down so you dont need to preload)

 

Hope I'm not too late with this post.

 

Liam

That does the trick. If you want the image to change on rollover then just copy the last block of CSS but just leave the "#rightHeader a:hover" as the identifier and change the image (or shift the image down so you dont need to preload)

 

Hope I'm not too late with this post.

 

Liam

 

hmm why have I never thought of that? I used to put a 1px X 1px transparent spacer gif in there and set it to 100% W&H and just put the a href on that or map it out. but your way sounds so much cooler 8)

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.