O'Reilly logo

Responsive Web Design with HTML5 and CSS3 by Ben Frain

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Fluid images

Making images scale with a fluid layout can be achieved simply for modern browsers (including IE 7+). It's as simple as declaring the following in the CSS:

img {
  max-width: 100%;
}

This makes any images automatically scale to up to 100 percent of their containing element. Furthermore, the same attribute and property can be applied to other media. For example:

img,object,video,embed {
  max-width: 100%;
}

And they will scale too, apart from a few notable exceptions such as <iframe> videos from YouTube but we'll wrestle those into submission in Chapter 4, HTML5 for Responsive Designs. For now though, we'll concentrate on images as the principles are the same, regardless of the media.

There are some important considerations in using this approach. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required