[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 850
  • Last Modified:

Scale image with aspect ratio css.

Dear Support,

I have a div containing a image, I'm using max-width and max-height to scale the image in the div,
but the problem is when the image has more height than width, it doesn't stretch correctly.

I have this application released in this link: Symbiont Technologies

To get to the image just follow this steps:

1. Sign In.
SignIn.jpg
2. Select the green 3 little men image.
Menu.jpg
3. Slide the Mark Ecko until the "styles->" word appears.
SelectCustomer.jpg
4. Select the style 90302 from the styles combobox.
SelectStyleCombobox.jpg
5. There is the image.
StyleImage.jpg
but in the other styles the images are fine, I believe that the problem has to be involved with the image height.

Thanks in Advance.

Best Regards.
0
Conrado ZAVALA
Asked:
Conrado ZAVALA
1 Solution
 
Conrado ZAVALAAuthor Commented:
If you click the image a popup is triggered with the image larger and in the popup it is displayed fine.
0
 
Ray PaseurCommented:
I don't see the "styles" combobox?  It seems to fly away when I drag the image in that row.
0
 
sbickerstaffCommented:
Are you using Bootstrap? The reason I ask is that within it, there are responsive images which will resize the image based on the screen / browser window size:

See http://getbootstrap.com/css/#images for info
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
MurfurFull Stack DeveloperCommented:
To keep it proportional when handling an array of images that may be different sizes, you need to set one dimension to be automatic. Bear in mind that one of the quirks of CSS is that using percentage with width and height styles relates to the available space i.e. within the parent container but max-height and max-width relate to the image itself i.e. width: 50% and max-width: 50% could well be two different numbers:
#imgStylesStyleImg {
    max-width: 130px
    height: auto
}

#frmImageStylesContainer {
    overflow: hidden
}

Open in new window

0
 
Conrado ZAVALAAuthor Commented:
Hi experts,

I have this div with the ID: "frmImageStylesContainer "  with a width of "130px" and a height of "130px" and it is also the image container.
What I really want is to fit the image inside that div keeping the aspect ratio, being the width and height of the container always the same.

Something like this:
Untitled.png
and this:
Untitled2.png
If you see the container always has the same size (it is a perfect square), the images changes size to fit the container keeping the aspect ratio.

That is what I want to do using the css in my app.

Thank you very much for your help.

Best Regards,
Rodrigo Rivera
0
 
Conrado ZAVALAAuthor Commented:
Hi sbickerstaff,

I'm not using bootstrap.

Thanks for your comment.
0
 
Conrado ZAVALAAuthor Commented:
Hi Ray Paseur,

Could you please give a try loading the app again.
What did you mean with "flew away in the drag of the image"?

Thanks for your comment.
0
 
MurfurFull Stack DeveloperCommented:
Even simpler, just edit the first element in your CSS file td.css, specifically adding max- to width - this works when I edit your code in FireBug. As I mentioned in my previous post, width relates to the parent container but max-width relates to the image itself.
.td-picture {
    max-width: 100%;
    display: block;
    margin: 0 auto!important;
}

Open in new window

0
 
RobOwner (Aidellio)Commented:
bootstrap does this to an image to make it responsive, note the width and height settings

display: block;
width: 100%;
max-width: 100%;
height: auto;

Open in new window

0
 
Conrado ZAVALAAuthor Commented:
Thank you very much for all the help.

Best Regards.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now