mpn
mpn

Reputation: 1018

inner border radius does not work

I have a question about border radius. Basically I am using code to create a sort of spotlight tool to find hidden html. Here is the 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;
}

I need to somehow set the border radius of the shape to make it appear as a circle. This is a problem however because this only effects the outside border, which is not something I want to effect. Just the inside of the border.

Upvotes: 4

Views: 114

Answers (4)

musicnothing
musicnothing

Reputation: 3985

Here's a simpler option:

Fiddle

Just put the border-radius on the original element.

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

Then just hide everything until the mouse has been over it.

body /* or whatever element you want */
{
    display:none;
}

Then do this:

$(document).bind('mouseenter', function (e) {
    $('body').show();
});
$('body').bind('mouseleave', function (e) {
    $(this).hide();
});

This way users will never see the hidden content.

Upvotes: 6

Jakub Kotrs
Jakub Kotrs

Reputation: 6244

This solutions is more general and should be used if the desired shape is rounded square or rectangle

Using a after pseudo-element: 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%;
}

You need the relative positioning to cover the left-upper edge that would otherwise still be visible. Beware of using box-model or browser inconsistency of calculation dimensions, this is working in webkit, might not be the case for IE.

Upvotes: 2

ricksmt
ricksmt

Reputation: 899

Without too much change: jsFiddle

In summary, set border-radius = border-width + radius.

Upvotes: 1

Chris Rasco
Chris Rasco

Reputation: 2731

Jakub is close, but this produces the intended circle.

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%;
}

Upvotes: 0

Related Questions