How to use CSS to control the image of the Web page adaptive size?

Source: Internet
Author: User
Tags valid
css| Control | Web Page | adaptive

The image automatically adapts to the size is a very common function, in the production time in order to prevent the picture to open the container and the picture size of the necessary control, we can use CSS to control the picture to make it adaptive size?

We think of a relatively simple solution, although not very perfect, if your request is not very high, already can meet your needs. Let's look at the following code:

div img {
max-width:600px;
width:600px;
Width:expression (document.body.clientwidth>600?) 600px ":" Auto ");
Overflow:hidden;
}

max-width:600px; In IE7, FF and other non IE browsers, the maximum width of 600px. However, it is not valid in IE6.


width:600px; The size of the picture in all browsers is 600px;


When the picture size is greater than 600px, it is automatically reduced to 600px. Valid in IE6.


Overflow:hidden; Beyond the part of the hidden, to avoid control of the image size failure caused by the distraction deformation.



Related Article

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.