I remember someone asked me this before, but I didn’t pay attention to it at that time. Now I finally encountered this problem. Because the img tag does not have an onload event. So the img in the UBB code uses onload to handle large This method cannot be used to adapt the image to the image.
But after testing, the body can still bring the onload event, so my solution is to process the image that is too large after the page is fully loaded.
So I wrote a simple code in JS
Related codes
function ReImgSize(){
for (j=0;j{
document.images[j].width=(document.images[j] .width>420)?"420":document.images[j].width;
}
}
Then add onload="ReImgSize( " Image adaptation.
We all know that Mozilla supports a max-width CSS syntax. So, we define the global style of the image like this
Related code
img{
max-width:100%;height:auto;
}
In this way, the image will automatically adapt to its size within the div or table.