CSS "cropping" the picture (showing part of the picture)

Source: Internet
Author: User

Background: A friend has a need, that is, the list page display of the picture to do the crop, or do not proportionally reduce the picture looks distorted. Originally think of a good solution is to use PHP to generate thumbnails, but tried several open source thumbnail class are not a satisfactory, suddenly think why not directly with CSS?

<style>    #sample {        width:100px;        height:100px;        Overflow:hidden;        position:relative;        border:1px solid black;    } </style><div id= "Sample" >     </div>

For example, if you have a picture that is 400x300 pixels, and then your list page is going to show a wide height of 100x100 pixels, what do you do?

1. Zoom out the image first, that is, set the height= "100px" of the IMG tag;

2. Crop, set the width height of the div enclosing the img tag to 100x100

3. Done!!!

CSS "cropping" the picture (showing part of the picture)

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.