1

as i read around the web, it's a valid html5 practice to wrap block elements inside <a> elements. i have a problem though.

my html

<a href="http://google.com" target="_blank">
<div> </div>
</a>

my css

div {
    background:#f00;
    height:100px;
    margin-left:10px;
    width:300px;
}

a {background:blue;}

the link actually works, but i see no blue background and chrome says that my a have no height and width

enter image description here

changing the css of the a to display:inline-block does the trick here, but not in my website.

enter image description here

do you have any suggestion or solution? how come the a element doesn't "follow" its child? thank you!

http://jsfiddle.net/72cYy/82/

valerio0999
  • 11,458
  • 7
  • 28
  • 56

1 Answers1

0

it depends on what you're looking for, you can set a to display:block if you want it to behave like a block element:

a {
   display: block;
   background:blue
}

EXAMPLE 1

or you could set it to display: inline-block to make it behave like it natrually would:

a {
   display: inline-block;
   background:blue
}

EXAMPLE 2

There is no reason that either of these wouldn't work on your site. Perhaps you have CSS or javascript overwriting it? Both of these methods will fix the collapsed height/width issue. If it is a conflicting CSS issue you could be more specific by adding an id or a class:

a#wrapper{
   display: inline-block;
}

or

a.wrapper{
   display: inline-block;
}

For more information on collapsed elements, you can check out this SO answer

Community
  • 1
  • 1
jmore009
  • 12,863
  • 1
  • 19
  • 34