我想根据该容器内的图像使用jquery或javascript来定义我的容器的高度。这可能吗?我的代码如下:如何通过该容器内的元素来定义容器的高度
<div class="img-info"> <img src="images/photos/thumb_sample_l.jpg" alt="sample" title="Sample thumbnail" width="100%" /> </div>
我想根据该容器内的图像使用jquery或javascript来定义我的容器的高度。这可能吗?我的代码如下:如何通过该容器内的元素来定义容器的高度
<div class="img-info"> <img src="images/photos/thumb_sample_l.jpg" alt="sample" title="Sample thumbnail" width="100%" /> </div>
的JavaScript代码来管理根据屏幕高度的内容高度可以对你有所帮助..
<script type="text/javascript">
$(document).ready(function() {
var scrheight=screen.availHeight;
//alert(scrheight-270);
$('.TabbedPanelsContent').css('max-height',scrheight-270);
$('.TabbedPanelsContent').css('overflow','auto');
});
</script>
在这里使用你的类名而不是TabbedPanelsContent会使你想要你想要的。
感谢abc123,这也将与我正在进行的项目一起使用。 – BeDesinged 2012-07-23 00:46:34
这个jQuery脚本应该做的伎俩
var imgHeight = $('.img-info img').height();
$('.img-info').css({'height':imgHeight});
通常,容器隐含地占用其内容的高度。 – Pointy 2012-07-22 04:01:58
浏览器自动计算css高度(和宽度,实际上)属性的默认值,使其足以容纳任何内容 – nbrooks 2012-07-22 04:03:03
也许OP正在尝试通过图像设置高度,然后让剩下的内容溢出与滚动条? – Matchu 2012-07-22 04:04:08