Home  >  Article  >  Web Front-end  >  How to Make Images Resize Automatically with Browser Size Using CSS?

How to Make Images Resize Automatically with Browser Size Using CSS?

DDD
DDDOriginal
2024-10-25 22:32:29799browse

How to Make Images Resize Automatically with Browser Size Using CSS?

Automatically Resize Images with Browser Size Using CSS

You want your images to resize automatically when you resize your browser window, but the provided code isn't working. Let's investigate a solution.

To make the images flexible, you'll need to add max-width: 100% and height: auto to them. However, IE8 has a bug where this doesn't work. To fix it, add width: auto\9 for IE8.

<code class="css">img {
    max-width: 100%;
    height: auto;
    width: auto; /* ie8 */
}</code>

Any images added using the img tag will now automatically resize.

To illustrate, here's an example JSFiddle that doesn't require JavaScript. It's compatible with the latest versions of Chrome, Firefox, and IE (based on testing).

The above is the detailed content of How to Make Images Resize Automatically with Browser Size Using CSS?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn