BeDesinged
BeDesinged

Reputation: 55

How to define height of a container by an element within that container

I'm trying to define the height of my container based off of the image within that container using jquery or javascript. Is this possible? My code is as follows:

<div class="img-info">
<img src="images/photos/thumb_sample_l.jpg" alt="sample" title="Sample thumbnail" width="100%" />
</div>

Upvotes: 1

Views: 290

Answers (2)

Srinivas V.
Srinivas V.

Reputation: 321

the javascript code to manage your content height according to the screen height may be helpful for you..

<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>

use your class name instead of TabbedPanelsContent here will made you want u want.

Upvotes: 0

alexndm
alexndm

Reputation: 2929

This jQuery script should do the trick

var imgHeight = $('.img-info img').height();
$('.img-info').css({'height':imgHeight});

Upvotes: 0

Related Questions