javascript - Proportional Scaling of Images in a Table -
i have html table width of 100%. table has 2 rows , 2 cells each. each cell contains same image width=100% , height=auto. image scales proportional inside cell.
here html:
<table cellspacing="0" cellpadding="0"> <tr> <td> <img src="http://idevicegazette.com/wp-content/uploads/2013/03/htc-one-sample-002-200x200.jpg" /> <div class="info"></div> </td> <td> <img src="http://idevicegazette.com/wp-content/uploads/2013/03/htc-one-sample-002-200x200.jpg" /> <div class="info"></div> </td> </tr> <tr> <td> <img src="http://idevicegazette.com/wp-content/uploads/2013/03/htc-one-sample-002-200x200.jpg" /> <div class="info"></div> </td> <td> <img src="http://idevicegazette.com/wp-content/uploads/2013/03/htc-one-sample-002-200x200.jpg" /> <div class="info"></div> </td> </tr> </table>
and here css:
table { width: 100%; } table td { width: 50%; position relative; } img { width: 100%; height: auto; }
to describe problem i've setup jsfiddle (best use chrome):
if start changing size of result window see there situations images in right column 1 pixel smaller in left column. goal images have exakt same size (the image in second column should have same width/height image on right side).
i'm aware problem issued when table width odd pixel number dosnt allow 2 images exakt same size. i'm searching somekind of workaround problem
maybe force table width number. this
width = window.innerwidth; if( width % 2 != 0 ){ width -= 1; } document.getelementbyid("tableid").width = width;
of course have accept slight assymetry when window width odd number.
Comments
Post a Comment