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.
Conrado ZAVALAAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
CSS

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.