Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9200237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:43:14+00:00 2026-06-17T22:43:14+00:00

I have an img element inside a liquid div . That img has its

  • 0

I have an img element inside a liquid div. That img has its max-height set to 100%. So, if the image is taller than the div, it should be rendered as tall as the div.

The original size of the .png file is 200×200. In my browser, the div shows as 284×123. Therefore, the img should be rendered at 123×123, to keep its aspect ratio.

However, the img is breaking the div’s bounds and still shows as 200×200.
I can’t seem to figure why this is happening.

This is happening on Chrome, but not on Firefox (last time I tried).

You can see the current state here (http://paginas.fe.up.pt/~ei07171/test/).
If you hover over the left side of the picture, you’ll see a grey arrow, the .png that i’m talking about. The arrow on the right side is a SVG file and works correctly.

Edit: I’ve created a separate jsfiddle (http://jsfiddle.net/dcastro/3Ygwp/1/), where the img’s max-height seems to work correctly.. I can’t find what on my project is causing it not to work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T22:43:16+00:00Added an answer on June 17, 2026 at 10:43 pm

    I figured it out. For an element’s max-height to work, one of its parents must have a height attribute defined (apparently in a fixed unit, like px, not in percentage).

    From the w3c specs:

    The percentage is calculated with respect to the height of the
    generated box’s containing block. If the height of the containing
    block is not specified explicitly (i.e., it depends on content
    height), and this element is not absolutely positioned, the percentage
    value is treated as ‘0’ (for ‘min-height’) or ‘none’ (for
    ‘max-height’).

    Since none of my img’s parent have a fixed height defined, I had to limit my img to max-width instead.

    Edit: Also, it seems webkit takes the specs a little too literally: https://stackoverflow.com/a/3808701/857807

    I used the workaround presented in that thread, and used position: absolute; max-height: 100%; top: 0.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a 48x48 div and inside it there is an img element, I
I have an element that's 60px tall that has other elements like an image
Let's say I have an img element inside a div , how do I
I have a website with a backgroundimage in a <div> element that has another
I've an image tag inside a div element. <div id = myDiv> <img alt
I have an element inside a div that is draggable jquery ui. And I
I have an img element with style='width:40%;height:40%;' . I would like to add a
I have an anchor element that looks like this <a href=url><img src=imgurl/>Text</a> I would
I have an image tag enclosed in an anchor element like this: <a href='$image'><img
I have a header element with 2 elements inside - an img and p

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.