CSS control picture Size-Fit Width _ Experience Exchange

Source: Internet
Author: User
Do not know home has not encountered such a situation: in the CSS control picture size, if the width of the picture is written dead, such as img{width:500px;}, of course, if the picture width is greater than 500px can be very good control it does not let it too large, but if the picture width is less than 500px, For example, only 100px, the previous wording will enlarge this picture 5 times times to show, obviously, this is not what we want to see.

So how can css differentiate between the size of these picture settings? Very simple, please see:

Copy Code code as follows:

Img{width:expression (this.width>500?) 500px ": this.width+" px "); }

As long as the use of this code in CSS, you can control large pictures and small pictures. It means that if the picture width is greater than 500px, then the picture is displayed in 500px size, if less than, then the picture is displayed according to the original size! What, is it really simple?

Disadvantages: Increase the load on the client, generally with JS to achieve more.
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.