CSS control picture Size-Fit Width _ Experience Exchange
Source: Internet
Author: User
Do not know whether the home has encountered such a situation: in the CSS control picture size, if the width of the picture to write dead, such as img{width:500px;}, if the width of the picture is greater than 500px can be very good control it does not make it too large, but if the picture width is less than 500px, For example, only 100px, just the writing will enlarge this picture 5 times times the display, obviously, this is not what we want to see.
So, how can css distinguish between the size of these images? Very simple, please see:
Copy the Code code as follows:
Img{width:expression (this.width>500? ") 500px ": this.width+" px "); }
As long as you use this code in CSS, you can control the big picture and the small picture separately. It means that if the image width is greater than 500px, then the image is displayed in 500px size, if less than, then the image is displayed according to the original size! What, is it really simple?
Disadvantages: Increase the load of the client, generally using JS to achieve more.
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