Reputation: 2718
I have a problem with div which placed inside of table cell. Cell has fixed height and div positioned relative with height:100%.
td {
height:80px;
width: 80px;
}
.cell_text {
display: table-cell;
vertical-align: middle;
width: 100%;
height: 100%;
position:relative;
}
The problem appears when i change div's content and div height becomes greater than cell height. Behavior for IE and FF is below:
And the following picture illustrates Chrome's behavior:
Chrome's behavior is exactly what I need, how can I make it work same way in IE and Firefox?
Upvotes: 2
Views: 2426
Reputation: 78671
I removed unnecessary markup and CSS, and now it seems to work fine.
position: relative
did not really make much sense, and the border-fix
div seemed to be unnecessary - and also caused the problem. Tables (and elements having display: table-cell
and the likes) are quite flexible when it comes to height
- simple block elements may not be, like in this case.
There was a lot of redundant CSS also, please see the Fiddle. Tested in Chrome, FF, IE9.
So this would be the markup:
<td class="border">
<div class="cell_wrapper">
<div class="cell_text">
line-1
</div>
</div>
</td>
And the relevant CSS:
#mytable td {
height:80px;
width: 80px;
text-align: center;
}
.cell_wrapper {
display: table;
height: 100%;
width: 100%;
}
.cell_text {
display: table-cell;
vertical-align: middle;
width: 100%;
height: 100%;
}
Upvotes: 2
Reputation: 425
Firefox offers some possibilities for controlling cell behaviors, but if you have to support IE7, you're out of luck. display: table-cell;
doesn't work in IE7 or earlier.
Upvotes: -1