0

I have div containing the background image but i want to make that image as clickable and pointed to somewhere site. Is it possible to do this in css or jquery HTML:

<div id="logincontainer">
</div>

css :

  #loginContainer {
        -moz-border-bottom-colors: none;
            -moz-border-left-colors: none;
            -moz-border-right-colors: none;
            -moz-border-top-colors: none;
            background: url("http://s3.buysellads.com/1237708/176570-1371740695.gif") 
            no-repeat scroll center center #FF660D;  /*for example */
            border-color: #FFFFFF;
            border-image: none;
            border-right: medium solid #FFFFFF;
            border-style: none solid solid;
            border-width: medium;
            left: 0;
            margin-left: auto;
            margin-right: auto;
            position: fixed;
            min-height:200px;
            right: 0;
            top: 0;
            vertical-align: super;
            width: 100%;
            z-index: 9999999;
        }

Here is the http://jsfiddle.net/a39Va/16/

I am not sure is there is a way to make the background image as clickable which is pointed in div? Any suggestion would be great.

2
  • No, not without adding a <a> or using JavaScript and the click event. Commented Sep 6, 2013 at 15:21
  • 1
    Not sure if this is the correct solution, but it will work, have a look at this Commented Sep 6, 2013 at 15:21

4 Answers 4

3

Just do something like:

<a href="whereYouWantToGo"><div id="loginContainer'></div></a>

Or you can do that as well via JavaScript and jQuery

$('#loginContainer').click(function(e) { <Whatever you want to do here> });
Sign up to request clarification or add additional context in comments.

Comments

1

You need to fix the z-index of the background element, and as others have said, add an anchor or a javascript action. Also, I added some sample of the rest of the content on the page. You need to see how the two interact with each other.

Here's an updated jsFiddle

HTML

<div id="loginContainer">
    <a href="#"></a>
</div>
<div class="content">
    <p>Something</p>
</div>

CSS

#loginContainer {
    background: url("http://s3.buysellads.com/1237708/176570-1371740695.gif") 
    no-repeat center #FF660D;
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    position: fixed;
    z-index: 1;
}
#loginContainer a {
    display: block;
    height: 100%;
    width: 100%;
}
.content {
    z-index: 2;
    position: relative;
    width: 200px;
    height: 100px;
    background: #fff;
    margin: 30px 0 0 30px;
}

1 Comment

As a side note, I don't like these sort of interactions. It is always frustrating to me when a web site makes the entire background, or a huge area of the page, clickable.
1

Here's a Fiddle

HTML

<div id="logincontainer" data-link="http://google.com"></div>

jQuery

$(function() {

  $('#logincontainer').hover(function() {

    var divLink = $(this).attr('data-link');

    $(this).wrap('<a href="' + divLink + '"></a>');

  });

});

Comments

1

Why not using an anchor ?

<a href="link" id="logincontainer">
</a>

i updated your jsFiddle

otherwise :

  • you can click on any element to behave like a link with jQuery.
  • you can surround your <div> in an anchor if you use the html5 <!DOCTYPE> ( Otherwise invalid )

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.