Crop an image to square using percentages and max widths

无人久伴 提交于 2019-12-04 07:21:42

using padding-bottom along with positioning and overflow:hidden you can create a responsive square container:

.field-content{
    width:80%;
    padding-bottom:80%;
    margin:1em auto;
    overflow:hidden;
    position:relative;
    background:#000
}

.field-content img {
   position:absolute;
   width:auto;
    min-width:100%;
    min-height:100%;
}

DEMO

jQuery DEMO center images when scaling

I tidied up some of the js allowing multiple images to be scaled and put 4 images on a simple grid

edd

You can do something like overflow:hidden I've made a square of 100px you can define your own size.

HTML

<div id="frame">
<img src="your image"/>
</div>

CSS

#frame{
width:100px;
height:100px;
overflow:hidden;
}

#frame img{
width:auto;
height:100%;
min-width:100px;
min-height:100px;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!