Making a Div a Link

Discussion in 'CSS' started by Sneakynarb, Oct 24, 2007.

  1. #1
    Say in CSS all i have is this:

    <div id="name"></div>

    #name{
    margin-left: 20px;
    margin-top: 10px;
    width: 387px;
    height: 78px;
    background-image: url(images/Name.png);
    }

    How could i make the whole div a link?

    Thanks, in advance.
     
    Sneakynarb, Oct 24, 2007 IP
  2. dvirhazout

    dvirhazout Active Member

    Messages:
    691
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    60
    #2
    #name a{
    margin-left: 20px;
    margin-top: 10px;
    width: 387px;
    height: 78px;
    background-image: url(images/Name.png);
    display:block;
    }

    #name {
    }

    and the html:
    <div id="name">
    <a href="#"></a>
    </div>
     
    dvirhazout, Oct 24, 2007 IP
    Sneakynarb likes this.
  3. soulscratch

    soulscratch Well-Known Member

    Messages:
    964
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    155
    #3
    You can simulate a block level element such as a div by making the anchor which is by nature inline, block.

    <a id="anchor" href="file.html">foo</a>

    a#anchor { margin:10px 0 0 20px; display:block; width:387px; height:78px; background:url(images/name.png) no-repeat; }
     
    soulscratch, Oct 24, 2007 IP
  4. Sneakynarb

    Sneakynarb Peon

    Messages:
    120
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I used dvir's method. Thanks to both of you. +rep to dvir.
     
    Sneakynarb, Oct 24, 2007 IP
  5. webdesigner

    webdesigner Well-Known Member

    Messages:
    489
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    110
    #5
    soulscratch's method would have been better here - both ways work, just less code whilst same result his way.
     
    webdesigner, Oct 24, 2007 IP
  6. anions

    anions Notable Member

    Messages:
    4,840
    Likes Received:
    179
    Best Answers:
    0
    Trophy Points:
    275
    #6
    Check this page out. I defined a div in the header, but the whole header is clickable.

    A
     
    anions, Oct 26, 2007 IP
  7. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #7
    Sure you have the right URL? That anchor isn't expanding in any browser I throw at it, so the header is NOT clickable.

    Sorry Charlie.
     
    deathshadow, Oct 26, 2007 IP
  8. anions

    anions Notable Member

    Messages:
    4,840
    Likes Received:
    179
    Best Answers:
    0
    Trophy Points:
    275
    #8
    Sorry 'bout that.

    Check this page - It opens up fine now, but my original problem still persists.

    Thanks :)
     
    anions, Oct 27, 2007 IP