Jitendra Vyas
Jitendra Vyas

Reputation: 152677

Intersection in CSS3

Is it possible to make a "hole" in an element (div, span) like this using CSS. I know I can do it with a transparent image but I'm just curious to know if it's possible in CSS.

body {padding:70px; background:url(http://ipadinsight.com/wp-content/uploads/2011/11/AirPlayMirroring_thumb.jpg)} 
div {background:red;border-radius:10px;width:400px;height:100px}​

Try at jsfiddle here http://jsfiddle.net/xqEV2/

enter image description here

Upvotes: 5

Views: 9955

Answers (3)

sandeep
sandeep

Reputation: 92793

Yes; you can do it with pure css. Like this:

body {padding:70px; background:url(http://ipadinsight.com/wp-content/uploads/2011/11/AirPlayMirroring_thumb.jpg);}

.parent {background:red;border-radius:10px;width:400px;height:100px;position:relative;}
.circle{

    float:right;
    position:absolute;
    right:-50px;
    top:0;
    bottom:0;
    width:50px;
    overflow:hidden;
}
.circle:after{
    content:"";
    width:40px;
    height:40px;
    -moz-border-radius:100px;
    display:block;
    border:red 50px solid ;
    margin-left:-45px;
    margin-top:-20px;
}

Check this live example

http://jsfiddle.net/xqEV2/4/

Upvotes: 6

Sjoerd
Sjoerd

Reputation: 75609

You can simulate a hole by setting the same background image for the hole as the underlying element. That does not make it really transparent.

http://jsfiddle.net/VJRFh/2/

Upvotes: 0

Bobby Lundquist
Bobby Lundquist

Reputation: 19

No, A DIV is a "solid object".

You can on the other hand use a transparent picture(png or gif) to make something look like a hole. you wont be able to interact with the layer underneth as long as you havent changed the z-index..

You maybe could use borders to make it look like a box and keep the background-color:transparent

Upvotes: -1

Related Questions