Filter (Advanced Search)
Downloads
0
Views
207
Video

Video is not available... Embedded is previous playlist.

Details

Using the max-width Property

If the max-width property is set to 100%, the image will scale down if it has to, but never scale up to be larger than its original size:

 

Responsive Image

"max-width:100%" prevents the image from getting bigger than its original size. However, if you make the browser window smaller, the image will still scale down.

Resize the browser window to see the effect.

Example

<img src="/images/cat.jpg" style="max-width:100%;height:auto;">


<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>

<h2>Responsive Image - Using the max-width Property</h2>
<p>"max-width:100%" prevents the image from getting bigger than its original size. However, if you make the browser window smaller, the image will still scale down.</p>
<p>Resize the browser window to see the effect.</p>

<img src="/images/cat.jpg" style="max-width:100%;height:auto;">

</body>
</html>



Ad