2

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

Cody Guldner
  • 2,882
  • 1
  • 22
  • 36
ihorko
  • 6,509
  • 25
  • 75
  • 112

2 Answers2

4

Add height:100% to the anchor CSS:

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

jsFiddle example

j08691
  • 197,815
  • 30
  • 248
  • 265
2

You can define the height of your ancor like this

a {height: 100%}
topless
  • 7,829
  • 11
  • 56
  • 85