CSS 中心裁剪的可变尺寸图像

发布于 2024-07-18 07:18:35 字数 162 浏览 5 评论 0原文

我正在尝试显示图像的裁剪中心区域并使其适用于不同尺寸的图像。

我成功地为包含图像的div设置了固定宽度并使用了overflow:hidden属性,这按照我希望的方式工作,除了这只显示图像的最左侧部分而右侧被隐藏之外。

我想要的是显示图像的中心部分并隐藏图像的左侧和右侧。

I am trying to display a cropped center area of an image and have it work for different size images.

I had success setting a fixed width for the div containing the image and using overflow:hidden property, this works the way I'd like it to except this only shows the leftmost part of the image and the right side is hidden.

What I'd like is to display the center part of the image and have the left and right sides of the image hidden.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

窝囊感情。 2024-07-25 07:18:35

我会采用使其成为背景图像的方法

.imghider {width:100px; background-image:url(./qed.jpg); background-position:center center;background-repeat:no-repeat;}

<div class="imghider"> </div>

至于不同的尺寸,您可以使用多个类或CSS表达式(或服务器端CSS生成)

我希望这会有所帮助。

I'd go with the approach of making it a background image

.imghider {width:100px; background-image:url(./qed.jpg); background-position:center center;background-repeat:no-repeat;}

<div class="imghider"> </div>

As for different sizes you could use several classes or CSS expressions (or server side css generation)

I hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文