在我的页面中,我显示来自提要的帖子。后期预览包含图像和内容。图像的宽度固定为150px,但我希望图像的高度等于内容的高度。post-preview的内容可能少于450个字符,这意味着它的高度将比其他帖子小。
这是可能使用jQuery吗?
这是我的代码:
<div id="post">
<div id="image">
<?php
$imgpath="timthumb.php?src=THE-IMAGE.PNG&h=91&w=150"; } ?>
<img border="0" src="<?php echo $imgpath; ?>"></img>
</div>
<div id="thepost2">
<?php echo mb_substr(strip_tags($entry->description), 0, 450, "UTF-8"); ?>
</div>
</div>
HTML
<div id="uniqueid" class="autoheight">
<img />
</div>
$('.autoheight img').css({height: $('#thepost2').height(), width:'150 px'});
如果你不指定宽度,它将设置宽度等于高度。因此,您将根据需要适当地指定宽度。它可能会改变图像的长宽比,可能看起来不太好。