Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jan 2008
    Posts
    42
    Thanks
    4
    Thanked 4 Times in 4 Posts

    Making a link "fill" it's parent...

    Let's say I have...

    Code:
    <div style="background-color:red;height:100px;width:100px;">
        <a href="page.php" title="Go to Page.">Click me</a>
    </div>
    Now, if I want to make it so clicking anywhere in the red div will follow the link inside it. I would do something... like this:

    Code:
    <div style="background-color:red;height:100px;width:100px;">
        <a href="page.php" title="Go to Page." style="display:block;height:100&#37;;width:100%;">Click me</a>
    </div>
    With that, clicking anywhere in the red div will follow the link. I know this... I also know that there are other ways to do it (I have a little trick that I do using the jQuery Javascript library sometimes).

    What I'd like to know is, is this an acceptable/the right way of doing it? Thanks.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,866
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    Code:
    <div style="background-color:red;height:100px;width:100px;">
        <a href="page.php" title="Go to Page." style="display:block;height:100&#37;;width:100%;">Click me</a>
    </div>
    If you give display:block to <a>, then you can directly apply fixed width and border to it. No need for <div>.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    AoR Zeta (01-13-2008)

  • #3
    New Coder
    Join Date
    Jan 2008
    Posts
    42
    Thanks
    4
    Thanked 4 Times in 4 Posts
    Now after Years of doing this kind of stuff, I'm wondering how in the hell I didn't think of that?

    Applying display:block to that a tag means that it's basically a div, a block-level element... just a clickable one.

    Yet I have ALWAYS done it the way I said in my first post. Guess who feels silly now?

    Thanks a lot.

  • #4
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,930
    Thanks
    6
    Thanked 1,041 Times in 1,014 Posts

  • #5
    New Coder
    Join Date
    Jan 2008
    Posts
    42
    Thanks
    4
    Thanked 4 Times in 4 Posts
    Lol, I never do. What I posted was basically pseudo-code. Completely valid pseudo-code that happens to actually be HTML but you get what I mean. It's like Lorem Ipsum; filler text.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •