Css Image proportional scaling implementation program

Source: Internet
Author: User

The methods for FF, OPERA, SAFARI, IE7, and IE8 are as follows:

The code is as follows: Copy code

 
Img {max-width: 100px; max-height: 100px ;}
Img {min-width: 100px; min-height: 100px ;}


IE6 and earlier versions use the expression attributes supported by the browser:

 

The code is as follows: Copy code
* Html img {/* for IE6 */
Width: expression (this. width> 100 & this. width> this. height? 100: auto );
Height: expression (this. height> 100? 100: auto );
}

 

In css, we need to wait for the proportional scaling image to be used for the css expression. scale: expression and this. offsetWidth> this. offsetHeight. See the example below.

The code is as follows: Copy code


Img {
Max-width: 600px;
Max-height: 600px;
Scale: expression (this. offsetWidth> this. offsetHeight )? (This. style. width = this. offsetWidth> = 600? "600px": "auto") :( this. style. height = this. offsetHeight> = 600? "600px": "auto "));
Display: inline! Important;
}
</Style>


In the above code, the width and height only provide a maximum value, which can be modified as needed. The third line is the scaling code, and the values inside should also be modified.

Although the above code is still completed by using JavaScript, it still feels good.


Note: for example, text cannot be selected, and the input box cannot be focused.

Therefore, change auto to true.

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.