How can I use CSS to control the adaptive size of images?

Source: Internet
Author: User

Automatic Image resizing is a very common function. When making images, you must control the image size to prevent them from being opened in the container, can we use CSS to control the image size to make it adaptive?
We have come up with a simple solution, although not perfect. If your requirements are not very high, they can already meet your needs. Let's look at the following code:

The code is as follows: Copy code
Div img {
Max-width: 600px;
Width: 600px;
Width: expression (document. body. clientWidth> 600? "600px": "auto ");
Overflow: hidden;

◎ Max-width: 600px; the maximum width of other non-IE browsers, such as IE7 and FF, is 600px. However, it is invalid in IE6.
◎ Width: 600px; the image size in all browsers is 600px;
◎ When the image size is greater than 600px, it is automatically reduced to 600px. Valid in IE6.
◎ Overflow: hidden; hide the excess part to avoid opening deformation caused by failed Image size control.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.