如果我明白你的问题正确,你想用CSS/HTML与height
和width
来调整图像不拉伸的图像。您想改为修剪它。
我很确定您正在寻找CSS中的clip
属性。混合clip
和width
和height
裁剪您的图像,使其不被拉伸,但裁剪以适合所需的width
和height
。 Read up more about clip
here.
这里是你要求为你需要的额外的代码(注意,它使用jQuery的,所以你需要嵌入这个工作):
<style>
.container { position: relative; overflow: hidden; }
.container img { position: absolute; }
</style>
<div class="container">
<img src="..."/>
</div>
<script type="text/javascript">
$image = $('.container img');
width = $image.width();
height = $image.height();
$image.css({
left: 0 - (width/2),
top: 0 - (height/2)
});
</script>
注意,我得到了第二个脚本从这个问题:Cropping images from center on the fly。
我很困惑,我真的不明白你的问题......你的代码应该工作。 – 2013-01-13 22:28:51
@DumbSearch,但它显然没有,这就是问题':P' – tkbx
@tkbx我认为他不希望它扭曲和拉伸,他希望它裁剪? – 2013-01-13 22:35:31