CSS Image resize question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AdultKing
    Raise Your Weapon
    • Jun 2003
    • 15601

    #1

    CSS Image resize question

    I am resizing an image using CSS so that always fits within the browser window displaying the image.

    The CSS I am using is

    Code:
    div#sized {	text-align: center; }
    div#sized img{	height: 90%; border: none; padding:15px; top: 10%; position: relative }
    the HTML is

    Code:
    <div id="sized"><a href="http://example.com"<img src="someimage.jpg" alt="image text" /></a></div>
    It works fine in Safari and Firefox, however will not work on the iPad or iPhone. On those devices it just shows the full sized image not constrained within the DIV.

    Does anyone have any idea on a better way to do this within the constraints of plain CSS and HTML ?
    Last edited by AdultKing; 06-11-2012, 11:45 PM.
  • Nevet
    Registered User
    • Dec 2011
    • 10

    #2
    You can use max-width to prevent the image from bleeding over the edge of the display area.

    Code:
    #sized img { max-width: 100%; }

    Comment

    • fris
      Too lazy to set a custom title
      • Aug 2002
      • 55679

      #3
      Originally posted by AdultKing
      I am resizing an image using CSS so that always fits within the browser window displaying the image.

      The CSS I am using is

      Code:
      div#sized {	text-align: center; }
      div#sized img{	height: 90%; border: none; padding:15px; top: 10%; position: relative }
      the HTML is

      Code:
      <div id="sized"><a href="http://example.com"<img src="someimage.jpg" alt="image text" /></a></div>
      It works fine in Safari and Firefox, however will not work on the iPad or iPhone. On those devices it just shows the full sized image not constrained within the DIV.

      Does anyone have any idea on a better way to do this within the constraints of plain CSS and HTML ?
      if its wordpress

      http://viewportindustries.com/blog/a...-in-wordpress/
      Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.

      Comment

      • acctman
        Confirmed User
        • Oct 2003
        • 2840

        #4
        photo / image auto resizing is simple...

        .photo img { width: 100% }
        .photo { width: 40% } // print can be any size you want the default to be and can be applied to a div as a class.

        Comment

        • AdultKing
          Raise Your Weapon
          • Jun 2003
          • 15601

          #5
          Thanks for all the replies. I've got it sorted now.

          Comment

          Working...