Results 1 to 9 of 9

Thread: images maximal width

  1. #1
    Join Date
    Nov 2007
    Posts
    151
    Thanks
    67
    Thanked 0 Times in 0 Posts

    Default images maximal width

    Hi,

    I have few images that I should display in my site and I don't know the original width of the images (they are changing dynamically).

    My problem is that I have specific width to the place the images should be published (530px).

    How can I resize (by CSS) all the images, that their widths are bigger than 530px? (I want that the images will be resized also by the proposional height)

    For example if some image is 1060px*200 it will resize it to 530*100.

    If you have any other idea using PHP it will be appreciated as well

    Thank you very much.

  2. #2
    Join Date
    Jan 2006
    Location
    Ft. Smith, AR
    Posts
    795
    Thanks
    57
    Thanked 129 Times in 116 Posts

    Default

    This is done easily enough with CSS... Simply define an absolute value for the width (530px), then define the height as "auto". This will ensure that the image is resized while keeping the correct pixel aspect ratio.


    Code:
    img {
    width:530px;
    height:auto;
    }
    However, the code above will resize ALL images on your page. I would suggest using a div or some sort of container to place the images in (which I'm assuming you already have if you have a set width that they need to be), once you have a container in place for the images, give it a "class" or "id" then specify ONLY images within that class or id with the code above...

    Like this:

    Code:
    .image_container img {
    width:530px;
    height:auto;
    }

    Then the HTML:
    Code:
    <div class="image_container">
    <img src="yourimage.jpg">
    </div>
    --------------------------------------------------
    Reviews, Interviews, Tutorials, and STUFF
    --------------------------------------------------
    Home of the SexyBookmarks WordPress plugin

  3. The Following User Says Thank You to TheJoshMan For This Useful Post:

    d-machine (09-24-2008)

  4. #3
    Join Date
    Nov 2007
    Posts
    151
    Thanks
    67
    Thanked 0 Times in 0 Posts

    Default

    First of all, Thank you very very much !!
    However, what should I do if the width of the image is already smaller than 530px?
    I don't want it to be re-sized to 530px

  5. #4
    Join Date
    Mar 2005
    Location
    Western Australia
    Posts
    148
    Thanks
    24
    Thanked 4 Times in 4 Posts

    Default

    You could try

    HTML Code:
    img {
         max-width:530px;
         height:auto;
    }
    max-width as that is what I have used but from what I can tell IE does not like max-width (or is that just IE6 - I forget) though there is a work-around

    HTML Code:
    img {
         max-width:530px;
         width:expression(document.body.clientWidth > 530? "530px": "auto" );
         height:auto;
    }
    Hope that helps

  6. The Following User Says Thank You to gwmbox For This Useful Post:

    d-machine (09-24-2008)

  7. #5
    Join Date
    Nov 2007
    Posts
    151
    Thanks
    67
    Thanked 0 Times in 0 Posts

    Default

    Thank you very much, but it is still resizing the smaller images on IE.
    Last edited by d-machine; 09-24-2008 at 10:38 AM.

  8. #6
    Join Date
    Mar 2005
    Location
    Western Australia
    Posts
    148
    Thanks
    24
    Thanked 4 Times in 4 Posts

    Default

    OK it must be an IE6 thing as

    HTML Code:
    img {
         max-width:530px;
         height:auto;
    }
    works for FF3 and IE7, then make a separate CSS file and add an if IE6 (or below) condition in your HTML

    HTML Code:
    <!--[if lte IE 6]>
         yourie6cssfile.css
    <![endif]-->
    and set the style in that css file to

    HTML Code:
    img {
         width:expression(document.body.clientWidth > 530? "530px": "auto" );
    }
    Hope that works

  9. #7
    Join Date
    Nov 2007
    Posts
    151
    Thanks
    67
    Thanked 0 Times in 0 Posts

    Default

    I'm sorry but this is just the same..

  10. #8
    Join Date
    Mar 2005
    Location
    Western Australia
    Posts
    148
    Thanks
    24
    Thanked 4 Times in 4 Posts

    Default

    Hmm - seems like an older IE issue - I can get it to work in IE 7 and FF2, FF3 and Google Chrome...

    If I can work it out I'll get back to you - unless someone else wants to enlighten us

    Cheers
    1st rule of web development - use Firefox and Firebug
    2nd rule - see the first rule
    --
    I like Smilies

  11. #9
    Join Date
    Mar 2005
    Location
    Western Australia
    Posts
    148
    Thanks
    24
    Thanked 4 Times in 4 Posts

    Default

    Ok got it and has been tested on IE6

    HTML Code:
    	 img {
    	 	max-width:530px !important;
    	 	max-height:530px !important;
    		/* Resize the image for IE6 */
    		width: expression(this.width > 530 ? 530: true);
    		height: expression(this.height > 530 ? 530: true);		
    	 }
    See test here http://dogsites.com.au/pick-up/tester.html

    Cheers
    1st rule of web development - use Firefox and Firebug
    2nd rule - see the first rule
    --
    I like Smilies

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •