是否可以用html实现图像剪切/遮罩效果+ CSS3?

发布于 2024-08-25 03:00:22 字数 607 浏览 5 评论 0原文

我正在尝试仅使用 html 和 css 在 250x250 的图像周围放置一个漂亮的边框。标记是这样的:

<div id="img-container"><img src="pic.jpg" border="0"/></div>

CSS 是:

#img-container {
    height: 225px;
    width: 225px;
    padding: 3px;
    border: 1px solid black;
    z-index: 10;
    position: relative;
    overflow: hidden;
    border-radius: 10px;
}

#img-container img {
    z-index: 5;
}

基本上,我希望 div 容器剪切超出其边界的图片边缘。这将使用 border-radius 属性(-moz-border-radius、-webkit-border-radius 等)实现圆角边缘效果 - 如果它确实有效或什至可以完成。寻找这方面的提示和技巧。谢谢。

而且,是的,我显然不是网页设计师:)

I'm trying to place a nice border around an image that's 250x250, using only html and css. The markup is this:

<div id="img-container"><img src="pic.jpg" border="0"/></div>

And the css is:

#img-container {
    height: 225px;
    width: 225px;
    padding: 3px;
    border: 1px solid black;
    z-index: 10;
    position: relative;
    overflow: hidden;
    border-radius: 10px;
}

#img-container img {
    z-index: 5;
}

Basically, I want the div container to clip the picture's edges that exceed its boundaries. This will achieve the rounded edges effect using the border-radius property (-moz-border-radius, -webkit-border-radius, etc) - if it actually works or could even be done. Looking for tips and tricks on this. Thanks.

And, yes, I'm obviously not a web designer :)

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

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

发布评论

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

评论(2

挽心 2024-09-01 03:00:22

是的,这是可能的,但您应该使用 CSS 将图像设置为 div 背景:

#img-container {
    height: 225px;
    width: 225px;
    padding: 3px;
    border: 1px solid black;
    background-image: url('pic.jpg');
    border-radius: 10px;
}

这是必要的,否则您将在图像周围看到可怕的白色边框(在 Google Chrome 中测试)。

Yes it's possible, but you should set the image as the div background using CSS:

#img-container {
    height: 225px;
    width: 225px;
    padding: 3px;
    border: 1px solid black;
    background-image: url('pic.jpg');
    border-radius: 10px;
}

This is necessary, otherwise you will get horrible white borders around the image (tested in Google Chrome).

凤舞天涯 2024-09-01 03:00:22

据我理解你的问题,删除该

#img-container img {
    z-index: 5;
}

部分应该可以解决问题。

或者您可以使用该图像作为背景图像:

#img-container {
    ...
    background: url(pic.jpg) no-repeat top left;
}

as far as I understood your question, deleting the

#img-container img {
    z-index: 5;
}

part should do the trick.

Or you could use the image as a background image:

#img-container {
    ...
    background: url(pic.jpg) no-repeat top left;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文