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 "; } |