Reputation: 13814
I'm trying to recreate the OOCSS media object in order to show an image next to some text. The media object uses overflow: hidden
to create a new block formatting context. This makes sure that the text doesn't wrap around the image.
However when my media object is positioned absolutely Firefox renders the text different from Chrome and Internet Explorer. Firefox seems to base the width of the media box solely on the width of the text instead of both the width of the image and the width of the text.
Chrome and Internet Explorer (imho expected behaviour)
Firefox
.media:after {
content: '';
display: block;
clear: both;
}
.media .img {
float: left;
margin-right: 8px;
}
.media .img img {
display: block;
}
.media .bd {
overflow: hidden;
}
See this codepen for the extended example.
I was wondering if anyone knew if there is a workaround for this and perhaps why Firefox renders this differently.
Upvotes: 1
Views: 237
Reputation: 222
Absolutely positioned elements are removed from the normal document flow, so they won't fill up 100% of their parent like regular static block level elements. Instead, they rely on their content width or a specified width. Firefox seems to apply the content width a bit differently than Chrome or IE, which is why it appears cut off.
Not sure of your use-case or what browsers you support, but you have a couple options:
display: table-cell
for media body. This has the caveat that your media object basically take up as much room as it can since it behaves like a table cell, which may not be what you're after.Upvotes: 1