Bug Tracker

Opened 14 years ago

Closed 12 years ago

#4827 closed bug (invalid)

img with %-unit inside of inline-block element inside of scaled element does not size properly- whooo

Reported by: eveningsky Owned by:
Priority: minor Milestone: 1.4
Component: core Version: 1.3.2
Keywords: inline-block css percent scale size nested Cc:
Blocked by: Blocking:


I realize this is a bit of an edge case, but it may point to other more important undiscovered issues. It takes a fairly complicated set of circumstances to occur.

Normally an image sized using percentage units will automatically scale if one of it's parents is scaled. If a static or relatively positioned img and an absolutely positioned image are both nested inside an inline-block element which is inside the element to be scaled, the static or relative image will either not scale along with or will scale only partially. I first noticed this with $.animate(), but since $.css() suffers the same, I would consider this a core issue.

The example is also complicated so I have commented frivolously.

<script type="text/javascript">
	// two of the same image overlayed with >50% opacity should look like one 100% opacity image
	// lowered opacity make the bug easily viewed as the two images split apart.
	// scale the ultimate parent up on mouseover and down on mouseout
		function(){	$(this).css({width:'400px'}); },
		function(){	$(this).css({width:'200px'}); }

<style type="text/css">
/* zero the padding to be sure this isn't the problem */
div, img {margin:0; padding:0;}

	/* if this is display: static the absolutely positioned img fills 100% of screen */
	position: relative;
	/* default width */
	width: 200px; 

/* The Culprit. Take this line out and the problem goes away. */
div.inlineBlock{display: inline-block;}

/* 100% width, should scale to 100% of containing element */
img{width: 100%;}

/* Occurs with one static or relative and one absolute.  Both static or both absolute cause no issues. */
img.scalesProperly{position:absolute; top:0; left:0;}


<div class="hoverAction">
	<div class="inlineBlock">
    	<!-- This image will either not scale or will scale to about 300px instead of 400px 
          -- I have not figured out what decides which.  In one case it scaled partially
          -- then using the exact same code with a different image, it did not scale at all.-->
        <img alt="" class="scalesPartially" src="assets/images/ron.png" />
        <!-- This image will scale properly to completely fill its 400px wide container -->
        <img alt="" class="scalesProperly" src="assets/images/ron.png" />

<!-- On mouseout both images will return to the same proper initial size. -->

Change History (1)

comment:1 Changed 12 years ago by snover

Resolution: invalid
Status: newclosed

Thanks for the report, but this is not a jQuery bug. jQuery doesn’t do anything except change the style properties of the object, so any issues you are having are with the browser or the CSS spec.

Note: See TracTickets for help on using tickets.