2

I want to create an inset border radius for an image using CSS if possible, I am posting this question because all of the solutions I found online so far were for text and using divs.

Here is what I wish to achieve:

enter image description here

Thanks!

jbutler483
  • 24,074
  • 9
  • 92
  • 145
odedta
  • 2,430
  • 4
  • 24
  • 51
  • In CSS level 4, we can use [`corner-shape: scoop`](http://dev.w3.org/csswg/css-backgrounds-4/#corner-shaping). But it is not implemented in well-known web browsers as of writing. – Hashem Qolami Mar 31 '15 at 06:52
  • That's not really helping me then Hashem :) – odedta Mar 31 '15 at 07:00
  • 2
    Maybe not today or tomorrow.. but somewhen and for the rest of out lives :-) – Hashem Qolami Mar 31 '15 at 07:02
  • possible duplicate of [CSS: borders with negative radius](http://stackoverflow.com/questions/20421666/css-borders-with-negative-radius) or [Is there any way to invert a rounded corner in CSS?](http://stackoverflow.com/questions/4012085/is-there-any-way-to-invert-a-rounded-corner-in-css?lq=1) – jbutler483 Mar 31 '15 at 08:05

1 Answers1

3

One way:

<div class="container">
    <div class="dot1"></div>
       <div class="dot2"></div>
      <div class="dot3"></div>
       <div class="dot4"></div>
    <img src='http://placehold.it/400x300'>
</div>

CSS:

.container {
    position:relative;
    margin:50px auto;
    width:400px;
}
.dot1 {
    background-color:white;
    width:50px;
    height:50px;
    border-radius:100%;
    position:absolute;
    left:-25px;
    top:-25px;
}
.dot2 {
    background-color:white;
    width:50px;
    height:50px;
    border-radius:100%;
    position:absolute;
    right:-25px;
    top:-25px;
}
.dot3 {
 background-color:white;
    width:50px;
    height:50px;
    border-radius:100%;
    position:absolute;
    right:-25px;
    bottom:-25px;
}

.dot4 {
 background-color:white;
    width:50px;
    height:50px;
    border-radius:100%;
    position:absolute;
    left:-25px;
    bottom:-25px;
}

Demo: http://jsfiddle.net/ofejxfj6/

You can tweak it a little (size of circles/dots and dimensions), but it is pretty close, IMHO.

sinisake
  • 11,240
  • 2
  • 19
  • 27
  • I saw you put a white background, is it possible to make it transparent? I tried it but I saw the effect was lost and I understand why of course... you are merely covering these parts with a white background. I assume there is not other way? Oh, and what does border-radius:100% mean? – odedta Mar 31 '15 at 06:49
  • 1
    There are probably better ways, this one is straight forward - and yes...50% for borders is ok, but, browsers do their job, if it is set to 100%, too... :) – sinisake Mar 31 '15 at 06:58
  • @odedta if you want it to be transparent, you'll need to look into masking: https://css-tricks.com/clipping-masking-css/ – Christian Mar 31 '15 at 06:59
  • 1
    check [this](http://jessica-eldredge.com/2014/09/07/border-radius-50-or-100-percent/) – Sushovan Mar 31 '15 at 07:05
  • @Christian: how well will this solution be supported by browsers for the issue I posted? I havn't seen it on the link you provided. – odedta Mar 31 '15 at 07:13
  • 1
    @odedta Masking is poorly supported. You either have to use solid colours (like this answer), or include the bevel in the image file itself. It's **impossible** to have transparent bevels with good cross-browser support. **Completely and utterly impossible**. – Christian Mar 31 '15 at 07:16
  • 1
    @odedta: See [can i use](http://caniuse.com/#feat=css-clip-path) for browser compat. – jbutler483 Mar 31 '15 at 08:09
  • Yeah, IE is totally not supported so it's not a good idea to use this solution. – odedta Mar 31 '15 at 09:09