tags:

views:

76

answers:

3

I have multiple images and i wnat to place all of them in a single line.How should i manipulate the width of images such that the sum of width of al images does not exceed the browser's width.??

A: 
var width = (window.width / numImages) - margin;
Duracell
what is padding.?? also the images are asymmetric...so if asssign the width of all the images to (window.width)/numImages.Some images get cut off...
Axesh Ajmera
Oops. I didn't figure you'd have different widths. Silly me. Padding should actually be 'margin'.
Duracell
A: 

To be able to target them all at the same time give them all the same class or go from a containing id and get them by node name. After targeting them get their widths.

To get the widths into variables with jquery:

var $allImages = $('img.myImages');//all images need the same class

var allImagesW = $allImages.width() * $allImages.length;//you might want to use .outerWidth() to account for borders and padding, and .outerWidth(true) to include margins.

var windowW = $(window).width();
Dale
I am not using jquery...i am using pure javascript
Axesh Ajmera
+1  A: 
unomi
This is very very close to a perfect solution. The only thing I would suggest is changing the while condition to "while (child)". As currently written, it won't act on the last image.
Ryan Kinal