如何在HTML / CSS中只显示图像的一部分? [英] How can I display just a portion of an image in HTML/CSS?

查看:157
本文介绍了如何在HTML / CSS中只显示图像的一部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我想要一种方式,只显示一个250x50像素的HTML中的图片的中央50x50像素。我怎么能这样做。此外,有没有办法这样做css:url()引用?


我知道CSS中的剪辑,但这似乎只适用于绝对定位。


Let's say I want a way to display just the the center 50x50px of an image that's 250x250px in HTML. How can I do that. Also, is there a way to do this for css:url() references?

I'm aware of clip in CSS, but that seems to only work when used with absolute positioning.

解决方案

One way to do it is to set the image you want to display as a background in a container (td, div, span etc) and then adjust background-position to get the sprite you want.

这篇关于如何在HTML / CSS中只显示图像的一部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆