html - 具有圆形边框半径的背景剪辑

标签 html css

如何在 background-clip: padding-box 上实现边框半径?

我有一个不透明的粗边框;但是,所有四个内 Angular 都是 90 度 Angular 。

<!DOCTYPE html>
<html>
<head>
    <title>Border</title>
    <style>
        body, html{
            width: 100%;
            height: 100%;
        }
        .image_frame{
            display: flex;
            width:50%;
            background: white;
            background-clip: padding-box;
            border: 20px solid rgba(0, 0, 0, 0.3);
            border-radius: 20px;
        }
    </style>
</head>
<body>
    <div class="image_frame">
        <img src="http://trudog.com/home/wp-content/uploads/2015/03/Shocked-Pups.jpg">
    </div>
</body>
</html>

最佳答案

background-clip: padding-box 的实现没问题。 .image_frame 父级的背景(在本例中为 body)确实应该在半透明边框下方可见。

这里的问题是你的边框宽度等于你的边框半径。结果,您的边框的内 Angular 将为 90 度,因为圆 Angular 基本上采用实心象限的形式。来自spec :

The padding edge (inner border) radius is the outer border radius minus the corresponding border thickness. In the case where this results in a negative value, the inner radius is zero.

如果您希望内 Angular 具有半径,您需要指定一个大于边框宽度的边框半径。对于 20px 的内半径和 20px 的 border-width,生成的 border-radius 是 40px:

.image_frame {
    display: flex;
    width: 50%;
    background: white;
    background-clip: padding-box;
    border: 20px solid rgba(0, 0, 0, 0.3);
    border-radius: 40px;
    overflow: hidden;
}

此外,您还需要设置overflow: hidden 以便圆 Angular 真正裁剪图像;查看我对 this question 的回答了解详情。

关于html - 具有圆形边框半径的背景剪辑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30677803/

相关文章:

javascript - 选择选项 1 时禁用选项 2

javascript - 简单地尝试使用 <span> 字符来调用 javascript 函数来关闭下拉菜单

html - 如何使负边距正常工作?

html - 修复第一个和最后一个 div css

javascript - Node.js 静态文件夹引用未加载 CSS

javascript - 为什么它读取[object Object]?

html - CSS:按钮可见性问题

jquery - float 列表项带有不需要的垂直间隙

javascript - 华丽的弹出式透明 png 为灰色

php - PHP/HTML Web 应用程序中的全局计数器变量