Scale Images Down to Fit a Column


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. var maxWidth = 320;
  2. var adjustmentSet = document.getElementById('col-main').getElementsByTagName('img');
  3. for (var i=0; i < adjustmentSet.length; i++) {
  4. if(adjustmentSet[i].width > maxWidth){
  5. adjustmentSet[i].removeAttribute('height');
  6. adjustmentSet[i].style.width = '100%';
  7. }
  8. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.