Make a Div into a link

Discussion in 'HTML & Website Design' started by ArizonaSEO, Aug 21, 2011.

  1. #1
    Im looking to how to do this , and nothing i try can get it accomplished.

    Ive googled everywhere I found this link and a person's solution got praises but I dont know how to implement it, he explains it but I the type to need to see and example and i can work from their.

    heres his sollution
    source


    If anyone can write this out please, sorry but im a noob to this. as always I thanks you guys for the help
     
    ArizonaSEO, Aug 21, 2011 IP
  2. mike30

    mike30 Well-Known Member

    Messages:
    887
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    140
    #2
    basic:
    this is all you need to make a link of a div.
     
    mike30, Aug 21, 2011 IP
  3. ArizonaSEO

    ArizonaSEO Peon

    Messages:
    105
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    that doesnt work the link and the div is offset
     
    ArizonaSEO, Aug 21, 2011 IP
  4. drhowarddrfine

    drhowarddrfine Peon

    Messages:
    5,428
    Likes Received:
    95
    Best Answers:
    7
    Trophy Points:
    0
    #4
    Note that is invalid HTML 4.01 but IS valid in HTML5 only.
     
    drhowarddrfine, Aug 22, 2011 IP
  5. raminn

    raminn Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    You can use element properties and events such as mouse hover and mouse click to implement anchor style div.
     
    raminn, Aug 22, 2011 IP
  6. liolbg

    liolbg Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    <div onclick="window.location = 'HREF'">here</div> ?
     
    liolbg, Aug 24, 2011 IP
  7. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #7
    A div is a block element - you can't make it a non-block (not offset) element. That throws a lot of beginners, trying to get 2 divs right next to each other. Just take out the div tags and make the content of the div the text in your link.
     
    Rukbat, Aug 24, 2011 IP
  8. mike30

    mike30 Well-Known Member

    Messages:
    887
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    140
    #8
    That is a quick solution... Also, you can style the link with <span> <p> or other tags.
     
    mike30, Aug 25, 2011 IP
  9. Howe

    Howe Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    The easiest way is to make the link fill the whole div - it's an inline element so you've got to overwride that with CSS. Here's a quick example:
    <div class="someClass"><a href="home.html" style="display: block;">Look! the whole div is clickable now!</a></div>
    Code (markup):
    It's the
     style="display: block;"
    Code (markup):
    That makes it fill the entire width of it's parent but you'll have to put all of the divs content inside the link otherwise they wont be clickable. You could add something like this to your CSS too:
    .linkFillParent { display: block; }
    Code (markup):
    So if you want to make a link fill it's parent in future, all you have to do is add
    class="linkFillParent"
    Code (markup):
    to your links :)

    You can also do stuff in css like:
    .linkFillParent#hover { background-color: #some-hex; }
    Code (markup):
    to change the background colour of the div. if the div has any padding or anything you can just add a #hover attribute to the parent id/class :)
     
    Howe, Aug 25, 2011 IP
  10. kanikakaminial

    kanikakaminial Peon

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    iyou can run it....
    <a href=""><div>your text</div></a>
     
    kanikakaminial, Aug 26, 2011 IP
  11. XeBii

    XeBii Peon

    Messages:
    77
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Simple, But Requires JavaScript Enabled

    <div onclick="window.location='http:// your link goes here'"> Hello im a 300X300 Div Click me :)</div>
     
    XeBii, Aug 26, 2011 IP
  12. creativewebmaster

    creativewebmaster Active Member

    Messages:
    654
    Likes Received:
    7
    Best Answers:
    4
    Trophy Points:
    78
    #12
    actually w3c will not support your idea. its a wrong coding style.
     
    creativewebmaster, Aug 27, 2011 IP
  13. yanaveis

    yanaveis Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    < href="link" ><div>your Text</div></a>
     
    yanaveis, Aug 27, 2011 IP