ihorko
ihorko

Reputation: 6945

Make anchor whole height of the div for display:block

I have simple html:

<div class='mydiv'>
    <a href='#'>Link</a>    
<div>

and css:

div.mydiv { height: 200px; width: 200px; background-color:red; }
div.mydiv a { display:block; color:yellow; background-color:green; }

I need anchor occupy entire space of the div, for that I added display:block; to my css, but occupies only top line of the div.

What is wrong and how can I fix that? Thanks

Upvotes: 3

Views: 3861

Answers (2)

topless
topless

Reputation: 8221

You can define the height of your ancor like this

a {height: 100%}

Upvotes: 2

j08691
j08691

Reputation: 207901

Add height:100% to the anchor CSS:

div.mydiv a {
    display:block;
    color:yellow;
    background-color:green;
    height:100%;
}

jsFiddle example

Upvotes: 4

Related Questions