1

How I can make following shape with a colored border:

round image with shaped edge

My first try was pure CSS but the attached code makes more an egg shape than a circle:

img {
    border: 2px #ff00ff solid;
    border-top-left-radius: 60% 50%;
    border-bottom-left-radius: 60% 50%;
    border-top-right-radius: 50% 20%;
    border-bottom-right-radius:50% 20%;
}
<img  src="https://d1wn0q81ehzw6k.cloudfront.net/additional/thul/media/4e34feee0acdc38a?w=400&h=400" style="width:100%">

Second try, working with SVG isn't supported in Opera and IE and I have no idea how to make borders. The "cut" doesn't work every time.

img {
    clip-path: url(#myClip);
}
<svg width="120" height="120"
     viewBox="0 0 120 120"
     xmlns="http://www.w3.org/2000/svg">

    <defs>
        <clipPath id="myClip">
            <circle cx="260" cy="256" r="256" style="fill:none;stroke:#00df0b;stroke-width:6"/>

        </clipPath>
    </defs>
</svg>
<img src="https://d1ra4hr810e003.cloudfront.net/media/27FB7F0C-9885-42A6-9E0C19C35242B5AC/0/D968A2D0-35B8-41C6-A94A0C5C5FCA0725/F0E9E3EC-8F99-4ED8-A40DADEAF7A011A5/dbe669e9-40be-51c9-a9a0-001b0e022be7/thul-IMG_2100.jpg" style="width:100%">
Robert Longson
  • 118,664
  • 26
  • 252
  • 242
  • [The Shapes of CSS](https://css-tricks.com/examples/ShapesOfCSS/) shows some amazing shapes you can make with pure CSS, e.g. the [facebook icon](https://css-tricks.com/examples/ShapesOfCSS/#facebook-icon) (and upvoted @jbutler483 answer for using this technique) – Stephen P Aug 19 '16 at 23:52
  • Possible duplicate of [How do I draw an incomplete circle with CSS and in it how to put a picture?](http://stackoverflow.com/questions/28673567/how-do-i-draw-an-incomplete-circle-with-css-and-in-it-how-to-put-a-picture) – Naeem Shaikh Aug 22 '16 at 05:46

2 Answers2

3

The simplest solution is probably just to make an SVG.

<svg width="400px" height="400px" viewBox="0 0 1 1"
     overflow="visible">
  <defs>
    <mask id="myMask" x="0" y="0" width="1" height="1"
          maskContentUnits="objectBoundingBox" fill="white">
      <path id="myPath" d="M 0.8 0.9 L 0.8 0.1 A 0.5 0.5 0 1 0 0.8 0.9 Z"/>
    </mask>
  </defs>
  <image xlink:href="https://d1ra4hr810e003.cloudfront.net/media/27FB7F0C-9885-42A6-9E0C19C35242B5AC/0/D968A2D0-35B8-41C6-A94A0C5C5FCA0725/F0E9E3EC-8F99-4ED8-A40DADEAF7A011A5/dbe669e9-40be-51c9-a9a0-001b0e022be7/thul-IMG_2100.jpg"
         x="0" y="0" width="1" height="1" mask="url(#myMask)"/>
  <use xlink:href="#myPath" fill="none" stroke="#f0f" stroke-width="0.01"/>
</svg>
Paul LeBeau
  • 97,474
  • 9
  • 154
  • 181
  • Great ! but ... No Support with Opera and IE unfortunally. I will give further feedback tomorrow when i try out your suggestion :) UPDATE: It works perfect, many thanks ! – MatzunaTata Aug 19 '16 at 21:07
  • @MatzunaTata Opera and IE both support this unless you need to support a really really old, obsolete and dangerous to use version of IE. – Robert Longson Aug 19 '16 at 21:11
2

You could use a pseudo element to create something like this:

div {
  height: 300px;
  width: 300px;
  position: relative;
  overflow: hidden;
  cursor: pointer;
  transition: all 0.4s;
}
div:hover {
  height: 500px;
  width: 500px;
}
div:before {
  content: "";
  box-sizing: border-box;
  position: absolute;
  top: 0;
  left: 15%;
  height: 100%;
  width: 100%;
  background: url(http://lorempixel.com/300/300);
  background-size: 100% 100%;
  border-radius: 50%;
  border: 10px solid tomato;
}
div:after {
  content: "";
  position: absolute;
  right: 0;
  top: 15%;
  height: 70%;
  background: tomato;
  width: 10px;
}
<div></div>
jbutler483
  • 24,074
  • 9
  • 92
  • 145