Reputation: 4412
I've got an image that can be changed by the user. He can upload any image to be displayed on a page.
I want to set a fixed rectangle that doesn't change its size whether the user uploads a 16x16 image or a 2048x2048 one.
So, the uploaded image would be resized to fit the fixed rectangle (an image smaller than the rectangle would stretch to fit and an image larger than the rectangle would shrink to fit).
HTML
<div class="float-left">
<img width="300" height="300" src="@ViewBag.imgPath" alt="Your pic" />
</div>
I tried to set the width
and height
properties of the img
element but it doesn't work. I have also tried to set the width and height of the div that contains it but no luck.
Upvotes: 0
Views: 735
Reputation: 859
Html styling doesn't use px. Also, you should do this in css rather than inline hardcoding or inline styles.
<div class="float-left">
<img width="300" height="300" src="@ViewBag.imgPath" alt="Your pic" />
<div class="centered bold">
@Session["userName"]
</div>
</div>
Upvotes: 2