Reputation: 4469
When adding a background image in a standard block display div
via pseudo classes like this:
.outer {
background-color: red;
text-align: center;
}
.outer:before {
background-color: blue;
display: inline-block;
width: 200px;
height: 200px;
content: " ";
}
the outer div ends up being padded by a few px at the bottom relative to the contained :before element. Is it possible to avoid this? The padding goes away if the content
is replaced by non-empty text, but then I'd need a way of making the text invisible.
Upvotes: 1
Views: 113
Reputation: 51
Add height to .outer and set pesudo height to 100% http://jsfiddle.net/7Ja5d/8/
.outer {
background-color: red;
text-align: center;
height: 200px;
}
.outer:before {
background-color: blue;
display: inline-block;
width: 200px;
height: 100%;
content: " ";
}
Also if you want to make text invisible just set "color: transparent;"
Upvotes: 0
Reputation: 141
Because your inner element is an inline-block it is observing the line height style, so just set:
.outer{ line-height: 0; }
Hope that helps
Upvotes: 1
Reputation: 105903
You have 2 ways to get rid of that space. (your generated box stand on baseline, like text. it leaves room for letters like : g,j,p,q,y).
vertical-align:top
or bottom
to your inline-box
http://jsfiddle.net/7Ja5d/2/block
http://jsfiddle.net/7Ja5d/1/Upvotes: 3