3

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,888
  • 1
  • 25
  • 36
ihorko
  • 6,855
  • 25
  • 77
  • 116
  • For li: http://stackoverflow.com/questions/6323465/anchor-in-list-elements-not-filling-available-space-with-displayblock-and-heigh, for table cell: http://stackoverflow.com/questions/3966027/make-link-in-table-cell-fill-the-entire-row-height – Ciro Santilli OurBigBook.com Nov 17 '14 at 08:55

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
  • 204,283
  • 31
  • 260
  • 272
2

You can define the height of your ancor like this

a {height: 100%}
topless
  • 8,069
  • 11
  • 57
  • 86