Css controls proportional scaling of images

Source: Internet
Author: User

Css style code
<Style type = "text/css">
Img {max-width: 500px; max-height: 500px; scale: expression (this. offsetWidth> this. offsetHeight )? (This. style. width = this. offsetWidth> = 500? "500px": "auto") :( this. style. height = this. offsetHeight> = 500? "500px": "auto"); display: inline! Important ;}
</Style>
In this example, all the img labels on the web page are scaled by default. If you want to scale a specific image, you only need to modify the css name and then call it on the web page.

For example, if you want to display a large image 1024*768 in a 100*100 container, you need to use the image scaling function at this time!

<Style type = "text/css">
Body {margin: 0; padding: 0 ;}
Img {
Border: none;
Max-width: 100px;/* FF IE7 */
Max-height: 100px;/* FF IE7 */
_ Width: expression (this. width> 100 & this. width> this. height? 100: auto);/* IE6 */
_ Height: expression (this. height> 100? 100: auto);/* IE6 */
}
</Style>
<Body> </body>


When scaling images and other ratios, you must align the bottom of the image. At this time, you can use absolute positioning!

When scaling an image to a specific column, you must center the image horizontally. In this case, you only need to add text-align: center; to the parent container!

The image scales proportionally and alignment at the bottom of the image. If you want to center the image horizontally, you can use table for the time being!

 

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.