...

View Full Version : Making a link "fill" it's parent...



AoR Zeta
01-13-2008, 04:13 PM
Let's say I have...



<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:



<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.

abduraooft
01-13-2008, 04:34 PM
<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>.

AoR Zeta
01-13-2008, 04:39 PM
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.

VIPStephan
01-13-2008, 05:46 PM
And by the way: Donít use click here as link text (http://www.google.com/search?q=click+here+link+text).

AoR Zeta
01-13-2008, 05:52 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum