Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS conditionally resize image based on width?

  • This topic is empty.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #32191

    is there a way to resize an image based on its width? for instance, if the image is 300px or larger, it would resize to 500px; if the image is less than 300px wide, then it would remain its original width..?

    i feel like it might be possible with javascript but i don’t really know javascript so i could be completely wrong. ideas?

    #52842
    jamygolden
    Member
    #52833

    i should clarify — i have a div with a width of 500px. contained in that div are many differently-sized images; i want to assign images that are 350px or larger to width: 100% and allow images smaller than 350px to remain as they are. is that possible?

    #52807
    jamygolden
    Member

    jQuery(javascript) would work:

    $(document).ready(function(){
    $('div img').each(function(){
    if($(this).width() > 350){
    $(this).css('width', '100%');
    }
    });
    });
    #52809

    you are amazing, thanks! works like a charm.

    #196896
    geedimensions
    Participant

    Is there any way to accomplish with scss? I have an image slider. If the image is profile instead of landscape I want to change the width to 100%.

    #196897
    Paulie_D
    Member

    You might do better starting a new thread rather than resurecting a dead thread from 4 years ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • The forum ‘CSS’ is closed to new topics and replies.