CSS高度:仅当元素的父级具有明确定义的高度时,才100%有效。例如,这将按预期工作:
td {
height: 200px;
}
td div {
/* div will now take up full 200px of parent's height */
height: 100%;
}
由于似乎您的
高度将是可变的,因此如果您在右下角的图标中添加了绝对定位的图像,该怎么办?
.thatSetsABackgroundWithAnIcon {
/* Makes the
a coordinate map for the icon */
position: relative;
/* Takes the full height of its parent
. For this to work, the
must have an explicit height set. */
height: 100%;
}
.thatSetsABackgroundWithAnIcon .theIcon {
position: absolute;
bottom: 0;
right: 0;
}
像这样的表格单元格标记:
yadayada
编辑:使用jQuery设置div的高度
如果您将保留
为的子代,则此jQuery片段将正确设置其高度:
// Loop through all the div.thatSetsABackgroundWithAnIcon on your page
$('div.thatSetsABackgroundWithAnIcon').each(function(){
var $div = $(this);
// Set the div's height to its parent td's height
$div.height($div.closest('td').height());
});