is there a css property that will fit an image with same proportions without resize?

Discussion in 'HTML & Website Design' started by jbourne84, Oct 16, 2012.

  1. #1
    I am fitting images to specific sizes, that are relatively small, but is there a way in html or css that would let me keep the original image the same (larger) size and fit it into the space i want if its the same proportions? This way when i reference the image again somewhere else (but at a larger size) i dont need two copies of the same image.

    Thanks
     
    jbourne84, Oct 16, 2012 IP
  2. billzo

    billzo Well-Known Member

    Messages:
    961
    Likes Received:
    278
    Best Answers:
    15
    Trophy Points:
    113
    #2
    Did you try specifying the image width: 100%? I did something similar to this years ago. I had a blog and what would happen is that large images would overflow the post content area and break the design. I set a width or max-width equal to 100% and that constrained large images to fit only inside the post area. Smaller images were unaffected.
     
    billzo, Oct 16, 2012 IP
  3. JamesColin

    JamesColin Prominent Member

    Messages:
    7,874
    Likes Received:
    164
    Best Answers:
    1
    Trophy Points:
    395
    Digital Goods:
    1
    #3
    just use img width="whatever" and it should resize the height accordingly to the proportion, at least that was the case on various browsers several years ago, I don't know if they changed that behavior, I don't use this anymore I much prefer to have two copies (generated automatically) to save on loading time when looking at the thumbnails.
     
    JamesColin, Oct 16, 2012 IP
  4. foamingone

    foamingone Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #4
    are you talking about sprit sheets ??? you can always make a huge sprit sheet something like 2000 x 2000 and add both images on it
     
    foamingone, Oct 16, 2012 IP
  5. scottlpool2003

    scottlpool2003 Well-Known Member

    Messages:
    1,708
    Likes Received:
    49
    Best Answers:
    9
    Trophy Points:
    150
    #5
    There's a couple of ways:

    Although this is a quick fix, I think in this day in age it's worth thinking about the actual size of your images. We're going mobile, mobile's cost data. Your website needs to be friendly for mobile devices otherwise you'll lose your audience or severely limit it.

    A way to do this, which I'm currently adopting is to make a website upload form and upon upload resize your images so you have 2 (or more) versions. E.g. upload whatever.gif which is 500x200px which is fine for normal computers, but crop a version to a smaller aspect ratio so you end up with whatever.gif and whatevermobile.gif similar names so you don't forget.
     
    scottlpool2003, Oct 18, 2012 IP
  6. ronitmathurseo

    ronitmathurseo Member

    Messages:
    98
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    43
    #6
    Use this code you will get your original image if you download it some where else. But if you want to make image relatively proportional to your webpage then use javascript it will change your image size but original size remains same.
     
    ronitmathurseo, Oct 22, 2012 IP