内部边框半径不起作用。

4
我有一个关于边框半径的问题。基本上我正在使用代码创建一种聚光灯工具来查找隐藏的html。这是fiddle: http://jsfiddle.net/pwneth/hj57k/1899/ css:
#tail {
border: 1000px solid #fff;
position: absolute;
float: left;
height: 100px;
width: 100px;
background-color: rgba(0,0,0,.0);
z-index: 100;
top: 0px;
left: 0px;
pointer-events:none;
-moz-box-shadow:    inset 0 0 20px #000000;
-webkit-box-shadow: inset 0 0 20px #000000;
box-shadow:         inset 0 0 20px #000000;
}

我需要以某种方式设置形状的边界半径,使其看起来像一个圆。然而,这是一个问题,因为这只影响外部边框,而我不想影响到这个。只想影响到边框内部。


4
不确定如何解决你的问题,但是你所做的很酷! - BenM
4个回答

6
这里有一个更简单的选择:
只需在原始元素上放置border-radius。

Fiddle

#tail
{
    /* ... */
    border-radius:100%;
}

然后只需将所有内容隐藏,直到鼠标经过它。
body /* or whatever element you want */
{
    display:none;
}

那么请这样做:
$(document).bind('mouseenter', function (e) {
    $('body').show();
});
$('body').bind('mouseleave', function (e) {
    $(this).hide();
});

这样,用户就永远看不到隐藏的内容。

2

如果期望的形状是圆角正方形或矩形,则应使用此解决方案

使用after伪元素: http://jsfiddle.net/hj57k/1903/

#tail {
    border: 1000px solid #fff;
    position: absolute;
    float: left;
    height: 100px;
    width: 100px;
    background-color: rgba(0,0,0,.0);
    z-index: 100;
    top: 0px;
    left: 0px;
    pointer-events:none;
}
#tail:after {
    -webkit-box-shadow: inset 0 0 20px #000000;
    -moz-box-shadow:    inset 0 0 20px #000000;
    box-shadow:         inset 0 0 20px #000000;
    border: 10px solid white;
    border-radius: 20px;
    content: '';
    display: block;
    height: 100%;
    left: -10px;
    position: relative;
    top: -10px;
    width: 100%;
}

您需要使用相对定位来覆盖左上角,否则仍然会可见。请注意使用框模型或浏览器计算尺寸的不一致性,这在Webkit中有效,但可能不适用于IE。


1

不需要太多改变:jsFiddle

总结一下,将 border-radius = border-width + radius


0
Jakub很接近,但这会产生预期的圆形。

http://jsfiddle.net/hj57k/1905/

#tail {
    border: 1000px solid #fff;
    position: absolute;
    float: left;
    height: 100px;
    width: 100px;
    background-color: rgba(0,0,0,.0);
    z-index: 100;
    top: 0px;
    left: 0px;
    pointer-events:none;
}
#tail:after {
    -webkit-box-shadow: inset 0 0 20px #000000;
    -moz-box-shadow:    inset 0 0 20px #000000;
    box-shadow:         inset 0 0 20px #000000;
    border: 50px solid white;
    border-radius: 999px;
    content: '';
    display: block;
    height: 100%;
    left: -50px;
    position: relative;
    top: -50px;
    width: 100%;
}

你说得对,但是在循环的情况下,Alex的解决方案甚至更好:D - Jakub Kotrs

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接