Reputation: 1523
normally, I used to adjust an image to a div depending of it's width and height attributes using background-image. Now I have the exactly opposite issue.
What I'm trying to do is adjust the div size to the image but with a maximum width and height. let's say that if image is 200x200, the div must be adjusted to this size but if image exceeds the 300x300, it must by limited.
Any idea of how should i do it?
Upvotes: 3
Views: 13663
Reputation: 59
What's the structure of your page?
I would guess you use something like this:
<div id="container">
<img src="img.jpg" />
</div>
<style>
#container {
display: inline-block;
border:1px solid blue;
max-width:300px;
max-height:300px;
}
</style>
Upvotes: 0
Reputation: 324620
You can apply the max-width
and max-height
style properties to the image element.
Depending on what you need to do with the containing element, this might work:
<div>
<div style="position: absolute;">Element content here</div>
<img src="image.png" style="max-width: 300px; max-height: 300px;" />
</div>
Upvotes: 1