1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

[HELP?][CSS] Possible to do a "If image is wider then xxx pxls, width=100%, else, nothing"

Discussion in 'Web Design' started by Zakk-, Mar 2, 2010.

  1. Zakk-

    Zakk- Junior Member

    Joined:
    Sep 16, 2009
    Messages:
    141
    Likes Received:
    15
    Okay, I pretty much explained it in the title, but here we go.

    I have been messing around with a wordpress theme to get it to fit my needs, however, I ran into a problem. The images in the posts cover up my sidebar as they are too large.

    What I would like to do, is to resize all images that are too wide, but leave the others as they are.

    So in pseudo code...
    Code:
    If
       image is over xxx pixels, 
           set the width to 100%
    else
       nothing
    


    Can anyone help me out?
     
  2. GetThatMoney

    GetThatMoney Registered Member

    Joined:
    Aug 20, 2007
    Messages:
    55
    Likes Received:
    7
    Not sure about css but...

    Code:
    <?php
    list($width, $height, $type, $attr) = getimagesize("your_image.jpg");
    
    if($width > $max_width){
    echo "<img src='your_image.jpg' style='INLINE CSS STYLING'>";
    } else {
    echo "<img src='your_image.jpg'>";
    }
    ?>
    
    Basically you want to let php check the images dimensions then if it's larger than your max width you echo an altered image html where you specify the CSS code inline and if it isn't then you echo the regular image code.