Zen Cart Logo
Forums / Templates, Stylesheets, Page Layout / Can I make background Image clickable link??

Can I make background Image clickable link??

Locked

Views: 9,888

Results 1 to 10 of 10
This thread is locked. New replies are disabled.
14 Aug 2009, 10:48 AM
#1
gaffettape avatar

gaffettape

Zen Follower

Join Date:
May 2009
Posts:
433
Plugin Contributions:
0

Can I make background Image clickable link??

I have recently been looking into making the background image on my site (localy hosted at the moment...sorry) a clickable link... alot of people say it's not possible, however I have found quite a few guides on the www explaining that this is possible? such as:

http://webdevnews.net/2007/01/css-trick-turning-a-background-image-into-a-clickable-link/

Can somone please confirm whether this is or isnt possible in Zen Cart and if it is please give me a little guidance on how it's done :smile:

Kind Regards.

14 Aug 2009, 11:16 AM
#2
schoolboy avatar

schoolboy

Totally Zenned

Join Date:
Jun 2005
Location:
Cumbria, UK
Posts:
10,327
Plugin Contributions:
0

Re: Can I make background Image clickable link??

Where are these background images being used on your site? Reason I ask is that the DIVS in Zencart are aready defined for styles in the php/html. If you alter these style ID's / Classes to get the effect you want, then you are going to have to re-declare their styles in the stylesheets.

I believe this can be done, but it will take a lot of care and attention to detail.

You will have to edit PHP files to put in the additional code as described at http://webdevnews.net/2007/01/css-trick-turning-a-background-image-into-a-clickable-link/ and your edited files should all be over-ride files, housed in your custom template.

14 Aug 2009, 2:01 PM
#3
gaffettape avatar

gaffettape

Zen Follower

Join Date:
May 2009
Posts:
433
Plugin Contributions:
0

Re: Can I make background Image clickable link??

Hi Schoolboy thanks for your reply,

The image im interested in making a clickable link is the header background image - in my case header_bg.jpg (was a .gif originally) I want to make it a link to the site homepage just like the Logo.

Regards

14 Aug 2009, 3:33 PM
#4
schoolboy avatar

schoolboy

Totally Zenned

Join Date:
Jun 2005
Location:
Cumbria, UK
Posts:
10,327
Plugin Contributions:
0

Re: Can I make background Image clickable link??

Why give yourself such headaches?

Just make your header_bg image your logo image as well...

What I do is create a new header_bg image and make it plain white, or some other neutral colour. I make it the same dimensions as the logo image and then tweak the stylesheet so that the logo sits exactly on top of the BG image - no padding, no margins.

If you want to do it by linking the header_bg image, then the file that will need editing is tpl_header.php.

The core file is in includes/templates/template_default/common

... and after you have edited it, you need to put the edited copy in:
includes/templates/YOUR_TEMPLATE/common.

See the Tutorials/FAQ for details on how to create over-ride folders (a custom template).

14 Aug 2009, 4:21 PM
#5
gaffettape avatar

gaffettape

Zen Follower

Join Date:
May 2009
Posts:
433
Plugin Contributions:
0

Re: Can I make background Image clickable link??

Hello again schoolboy,

Sorry but I'm struggling to understand the suggestion you made, I really cant work out exactly what it is you suggesting I do (sorry..!)
My site width is set to 100% at 1024x748 and above... I dont know if this changes anything ?

Regards :smile:

24 Sep 2009, 7:13 PM
#6
eric47905 avatar

eric47905

New Zenner

Join Date:
Sep 2009
Posts:
24
Plugin Contributions:
0

Re: Can I make background Image clickable link??

Here is your answer. Simple, and quite effective. I tested it on my shop because I was looking for the same thing you were.

The only thing I changed was to put the closing link tag "</a>" just before the closing div "</div>" tag of the logowrapper section instead of right after the closing span tag as shown.

I found this answer at http://webdevnews.net/2007/01/css-trick-turning-a-background-image-into-a-clickable-link/


It’s simple to turn a regular image into a clickable link, but in some situations, it’s just not possible to use a regular image – so how do you turn a background image into a clickable link? First let’s take a look at my original markup (I’ve removed unnecessary elements for sake of simplicity):

(This is found in /template_default/common/tpl_header.php)(The dots just symbolize stuff between the div tags)

<div id="logowrapper">.................</div>

(The following is found in /YOUR_TEMPLATE/css/stylesheet.css)(THis may not be exactly what you have, but you get the idea)

#logowrapper {
background: #fff url(images/header.png) no-repeat;
height: 101px;
width: 800px;
}

So, how can we make our background image a clickable link? It turns out it can be done with a clever CSS trick. All we have to do is add the link markup between our header div tags, and apply the above markup to the link instead. All we have to add to the CSS is display: block to force the link to fill the entire space.

To handle browsers that don’t support CSS (those things are still around?), we should also add a span containing link text that we will hide with our CSS. Here’s what we end up with:

(This is found in /template_default/common/tpl_header.php)(The dots just symbolize stuff between the div tags)

<div id="logowrapper"><a href="http://mysite.com"><span>MySite.com</span></a>.......</div>

(The following is found in /YOUR_TEMPLATE/css/stylesheet.css)(THis may not be exactly what you have, but you get the idea)

#logowrapper a {
background: #fff url(images/header.png) no-repeat;
display: block;
height: 101px;
width: 800px;
}
#logowrapper a span {
visibility: hidden;
}

And there you have it – a quick CSS trick that turns your background images into clickable links.

24 Sep 2009, 9:31 PM
#7
eric47905 avatar

eric47905

New Zenner

Join Date:
Sep 2009
Posts:
24
Plugin Contributions:
0

Re: Can I make background Image clickable link??

There was a small typo in the post I made in the following section.

eric47905:

#logowrapper a span {
visibility: hidden;
}

And there you have it – a quick CSS trick that turns your background images into clickable links.

Make sure that #logowrapper has the capital W not lowercase, to match the logoWrapper tag above it.

so it should look like...

#logoWrapper a span {
visibility: hidden;
}

25 Sep 2009, 3:02 AM
#8
askcilmum avatar

askcilmum

New Zenner

Join Date:
Sep 2009
Posts:
1
Plugin Contributions:
0

Re: Can I make background Image clickable link??

eric47905:

Here is your answer. Simple, and quite effective. I tested it on my shop because I was looking for the same thing you were.

The only thing I changed was to put the closing link tag "</a>" just before the closing div "</div>" tag of the logowrapper section instead of right after the closing span tag as shown.

I found this answer at http://webdevnews.net/2007/01/css-trick-turning-a-background-image-into-a-clickable-link/


It’s simple to turn a regular image into a clickable link, but in some situations, it’s just not possible to use a regular image – so how do you turn a background image into a clickable link? First let’s take a look at my original markup (I’ve removed unnecessary elements for sake of simplicity):

(This is found in /template_default/common/tpl_header.php)(The dots just symbolize stuff between the div tags)

<div id="logowrapper">.................</div>

(The following is found in /YOUR_TEMPLATE/css/stylesheet.css)(THis may not be exactly what you have, but you get the idea)

#logowrapper {
background: #fff url(images/header.png) no-repeat;
height: 101px;
width: 800px;
}

So, how can we make our background image a clickable link? It turns out it can be done with a clever CSS trick. All we have to do is add the link markup between our header div tags, and apply the above markup to the link instead. All we have to add to the CSS is display: block to force the link to fill the entire space.

To handle browsers that don’t support CSS (those things are still around?), we should also add a span containing link text that we will hide with our CSS. Here’s what we end up with:

(This is found in /template_default/common/tpl_header.php)(The dots just symbolize stuff between the div tags)

<div id="logowrapper"><a href="http://mysite.com"><span>MySite.com</span></a>.......</div>

(The following is found in /YOUR_TEMPLATE/css/stylesheet.css)(THis may not be exactly what you have, but you get the idea)

#logowrapper a {
background: #fff url(images/header.png) no-repeat;
display: block;
height: 101px;
width: 800px;
}
#logowrapper a span {
visibility: hidden;
}

And there you have it – a quick CSS trick that turns your background images into clickable links.

I really have got a lot of useful info from you ideas. Thank a lot !


[Calcul taux pret personnel en ligne - Demande et simulation de

financement de credit personnel](http://pretpersonnelenligne.org)

22 Oct 2009, 12:35 PM
#9
gaffettape avatar

gaffettape

Zen Follower

Join Date:
May 2009
Posts:
433
Plugin Contributions:
0

Re: Can I make background Image clickable link??

Hi eric47905

I was just going over a few older questions I had asked and only just realised you had written this fantastic guide on how to add a link to a background image... a big thanks for that :smile:

Sorry about the late reply but I thought I had subscribed to this thread... apparently not!!

Regards.

20 Apr 2010, 11:40 PM
#10
kburner avatar

kburner

Totally Zenned

Join Date:
Apr 2008
Location:
Flint, Michigan
Posts:
684
Plugin Contributions:
0

Re: Can I make background Image clickable link??

I can not seem to get this to work with my stylesheet. Keeps moving my whole header over to right side of screen when I add the "a" to it. I also tried to take out text-align and position and made it worse.

#logoWrapper {
width: 1000px;
height: 110px;
background: #fff url(../images/header_bg.jpg)no-repeat;
display: block;
text-align: center;
position: relative;
}

#logoWrapper a span{
visibility: hidden;
}

includes/template/common/tpl_header.php

<div id="logoWrapper">
    <div id="logo"></a><?php echo '<a href="' . HTTP_SERVER . DIR_WS_CATALOG . '">' . zen_image($template->get_template_dir(HEADER_LOGO_IMAGE, DIR_WS_TEMPLATE, $current_page_base,'images'). '/' . HEADER_LOGO_IMAGE, HEADER_ALT_TEXT) . '</a>'; ?><a href="http://burnerbooks.com"><span>Burnerbooks.com</span></div>

I put the code at the end. Any suggestions?

Kim