Consider this simple example.
HTML
<div>
<a href="/">Some link here</a>
<div>a div here</div>
<a href="/">Another link</a>
<br/>
<a href="/">And one more!</a>
</div>
CSS
div > a, div > div {
color: white;
line-height: 1.6;
height: 30px;
text-align: center;
width: 150px;
}
div > a {
border: 1px solid black;
display: inline-block;
text-decoration: none;
}
div > a:first-child {
background-color: red;
margin-bottom: -8px;
}
div > div + a {
background-color: green;
margin-bottom: -8px;
}
div > br + a {
background-color: blue;
}
div > div {
background-color:black;
border: 1px solid gray:
margin-bottom:-8px;
}
Fiddle here http://jsfiddle.net/rHupy/2/
This issue relates to latest Chrome and Firefox.
I've lost my whole afternoon yesterday fiddling with this. Basically, in this example the negative bottom margin acts very strangely. If you use the negative margin on the red A tag, it will draw in the DIV tag, but up to 8px. If you go below -8px (a more negative value, that is) the DIV tag stays put, it's not drawn more into the red A tag.
Applying the margin to the DIV tag works as expected, that is you can make the green A tag completely cover the DIV tag with -25px.
I'm quite certain this is related to the inline-block display style, because if I apply the block display style to all tags and omit the BR tags this problem is circumvented, but more arise. Example here http://jsfiddle.net/rHupy/3/
I have also tried combining the block display style with float left style, but that gave me more problems; some elements would just collapse, instead of aligning one to another.
My question is: why is the negative margin applied on A tag with inline-block display style set "limited" to some value?