CSS code for automatically controlling the image size

Source: Internet
Author: User

Css prevents image sizes from being too large

Add the following CSS:

The code is as follows: Copy code

Img {
Max-width: 800px;
Height: auto;

In the code, max-width: 800px limits the maximum image width to 800 pixels, while the following hight: auto is critical to ensure that the image has a correct aspect ratio, it will not be deformed due to the adjusted width.

Example

WordPress automatically adjusts the image size

1. Open your "style sheet (style.css)" file, and add the following code in p img {or similar places (you can change all 550 to the desired width)

The code is as follows: Copy code

P img {
Max-width: 550px;
Width: expression (this. width & gt; 550? "550px": true );
Height: auto;
}

2. Clear the cache!
3. Some earlier versions of IE are not supported.

If you want to work part-time on all browsers, jq or js is the best solution.

The code is as follows: Copy code

// Method: setSelectReadOnly is used to set the pole select control ReadOnly,
// This simulated read-only is not really read-only.
// Onbeforeactivate, onfocus, onmouseover, and onmouseout events are used.
// Example: ;
// Create by sl
//---------------------------------------------------
Function ImgAutoSize (imgD, FitWidth, FitHeight)
{
Var image1 = new Image ();
Image1.onload = function ()
{
If (this. width> 0 & this. height> 0)

If (this. width/this. height> = FitWidth/FitHeight)

If (this. width> FitWidth)

ImgD. width = FitWidth;
ImgD. height = (this. height * FitWidth)/this. width;

Else

ImgD. width = this. width;
ImgD. height = this. height;


Else

If (this. height> FitHeight)

ImgD. height = FitHeight;
ImgD. width = (this. width * FitHeight)/this. height;

Else

ImgD. width = this. width;
ImgD. height = this. height;


}
Image1 = null;
}

Image1.src = imgD. src;
ImgD. style. cursor = 'hand ';
ImgD. onclick = function () {openWin (this. src, 'imgphoto ', 600,400 )};
ImgD. title = "Click to view the original image in a new window ";
}

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.