100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > html中css设置td高度 如何使div填充td高度

html中css设置td高度 如何使div填充td高度

时间:2023-04-24 14:38:09

相关推荐

html中css设置td高度 如何使div填充td高度

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());

});

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。