Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatic resize of images in HTML5 CSS3 for iPad

Tags:

html

css

webkit

I am building a custom app for the iPad and can use webkit specific code. I'm having difficulty with dynamic resizing images to fit within a specific div container. Is there code to do this? Also is the code to recrop an image with a mask if the image is portrait or landscape?

like image 672
beactive Avatar asked Dec 27 '10 05:12

beactive


People also ask

How do I Auto size an image in CSS?

Answer: Use the CSS max-width Property You can simply use the CSS max-width property to auto-resize a large image so that it can fit into a smaller width <div> container while maintaining its aspect ratio.

How do I resize an image in html5?

One of the simplest ways to resize an image in the HTML is using the height and width attributes on the img tag. These values specify the height and width of the image element. The values are set in px i.e. CSS pixels. For example, the original image is 640×960.

How do I resize an image in css3?

We can resize the image by specifying the width and height of an image. A common solution is to use the max-width: 100%; and height: auto; so that large images do not exceed the width of their container. The max-width and max-height properties of CSS works better, but they are not supported in many browsers.


1 Answers

The easiest way to automatically resize an image with simple CSS:

img {
     max-width: 100%;
}

No CSS3 or HTML 5 magic required. Here's a blog post with more information, and some JavaScript that improves scaling in IE: http://unstoppablerobotninja.com/entry/fluid-images/

like image 189
derekerdmann Avatar answered Oct 20 '22 14:10

derekerdmann