7

I want to get a custom-shape image as shown here:

rounded image

#oval-shape {
  width: 200px;
  height: 100px;
  background: blue;
  -moz-border-radius: 100px / 50px;
  -webkit-border-radius: 100px / 50px;
  border-radius: 100px / 50px;
}
<img id="oval-shape" src="http://d152j5tfobgaot.cloudfront.net/wp-content/uploads/2014/04/internship_yourstory.jpg">

DEMO

Any thoughts if this is even possible?

6
  • what do you mean "is this even possible"? Didn't you just do it? What about the DEMO you linked to isn't doing what you want? Commented Jun 1, 2016 at 20:55
  • No. The shape isn't right. The image has more curve towards the top. Commented Jun 1, 2016 at 20:57
  • Your question asks for an oval shape. The demo creates an oval shape. The image in the question is not an oval shape. I don't know what shape that is, but it's not an oval. So you're saying you want to modify the demo to create the shape in the image in the question? I suggest you rephrase your question to remove the confusion. Commented Jun 1, 2016 at 20:59
  • Do you know that the image you are showing as what you want is even using CSS to do this? Commented Jun 1, 2016 at 20:59
  • I don't know how to frame the question to sound it like I want. To answer mrunion, the design is made in photoshop. If it's done in css, i would copy-paste the code and won't be asking here! Commented Jun 1, 2016 at 21:00

9 Answers 9

4

There is one way you can "fake" this shape with border:

body {
  background: purple;
}
#oval-shape {
  display:block;
  margin: 20px auto;
  width: 200px;
  height: 200px;
  background: none;
  border-radius: 100%;
  box-sizing: border-box;
  border-bottom: 50px solid transparent;
}
<img src="http://d152j5tfobgaot.cloudfront.net/wp-content/uploads/2014/04/internship_yourstory.jpg" id="oval-shape">

Sign up to request clarification or add additional context in comments.

4 Comments

Interesting. I used a transparent background and got it the way I want. I'm still trying to figure out how you manage to pull this off. Thank you so much :)
@ElaineByene oh ! Thanks for point that ... I haven't tried the transparent bg just works :) .. the warning is wrong XD
After testing with another image (square), I realize this method distorts the original image :(
@ElaineByene that is for the fixed values on height and width ... maybe. Post it on a fiddle maybe I can help u; you can also use the img's as background and cover on divs.
3

Use the below border properties and adjust as per your needs. More number means more towards circle. Hope it helps

#oval-shape {
  width: 200px;
  height: 100px;
  background: blue;
  border-top-left-radius:150px;
  border-top-right-radius:150px;
  border-bottom-left-radius:80px;
  border-bottom-right-radius:80px;
}

3 Comments

Thanks but that's far from what I want. Please check the screenshot again.
@ElaineByene That gives you an answer regarding the right way to make custom-shape images using css. You will have to experiment with the property values px/% yourself in order to find the shape closest to what you want. +1
No! I already had that and have played with it for hours before posting here.
2

Alternative approach with an inline svg. The following example uses 2 cubic bezier curves to make the desired shape and the pattern element to fill the shape with the image:

svg{width:30%;height:auto;}
<svg viewbox="0 0 10 8">
  <defs>
    <pattern id="img" patternUnits="userSpaceOnUse" width="20" height="10">
      <image xlink:href="http://d152j5tfobgaot.cloudfront.net/wp-content/uploads/2014/04/internship_yourstory.jpg" x="-1" y="0" width="14" height="7" />
    </pattern>
  </defs>
  <path fill="url(#img)" d="M0.7 5 C1 -0.8 9 -0.8 9.3 5 C9.3 7.5 0.7 7.5 0.7 5"/>
</svg>

2 Comments

Pretty nice solution ... Seems like you really know about SVG. Can you guide me where to start with that?
@DaniP I would suggest to start here. If you want to chat about it or have questions, you can come to this chatroom, people will help if they can.
2

You can indeed get that exact shape with no straight edges: http://jsfiddle.net/XDLVx/339/

#oval-shape {
    width: 200px;
    height: 100px;
    border-radius: 100px / 70px 70px 30px 30px;
}

More info: http://www.w3schools.com/cssref/css3_pr_border-radius.asp

Comments

0

Sure...here you go. Adjust as required.

#oval-shape {
  width: 200px;
  height: 100px;
  background: blue;
  border-top-left-radius: 150px;
  border-bottom-left-radius: 50px;
  border-top-right-radius: 150px;
  border-bottom-right-radius: 50px;
}
<img src="http://d152j5tfobgaot.cloudfront.net/wp-content/uploads/2014/04/internship_yourstory.jpg" id="oval-shape">

1 Comment

No. This isn't what I'm looking for. Also, I have been trying to adjust as required/shown in the screenshot here. The adjustment is what is making me go nuts.
0

Option 1

#ovalshape{
    -webkit-clip-path: polygon(51% 27%, 71% 36%, 91% 53%, 89% 68%, 76% 78%, 49% 85%, 16% 78%, 8% 65%, 15% 46%, 33% 33%);
    clip-path: polygon(51% 27%, 71% 36%, 91% 53%, 89% 68%, 76% 78%, 49% 85%, 16% 78%, 8% 65%, 15% 46%, 33% 33%);
}

Option 2: Take the image you want and cut out the inside and make transparent.

 <div style="height: 100; width: 100; overflow: hidden; background-image: url'picture.jpg';>
     <img src="cutout.png" style="height: 100%; width: 100%;">
 </div>

3 Comments

I don't understand your code. what is src="cutout"? and what is clip-path?
on that image you posted, at the person and cut them out and make it transparent. then save the image as cutout.png and use that for the source. Clip-path has nothing to do with option two, they are do different options.
cutting out is out of question since it will be a dynamic image in JPG format. Can you give a demo of that clip-path? I fail to understand the code.
0

#oval-shape {
  width: 200px;
  height: 100px;
  background: blue;
  -moz-border-radius: 100px / 50px;
  -webkit-border-radius: 100px / 50px;
  border-radius: 100px / 50px;
}
<img id="oval-shape" src="http://d152j5tfobgaot.cloudfront.net/wp-content/uploads/2014/04/internship_yourstory.jpg">

1 Comment

What's the point of this answer? Isn't it same as the code in question?
0

as others answers , border-radius can do it:

demo below, with both image on top of each others and side by side:

img {
  border-radius:200px 200px 180px 180px / 190px 190px  80px 80px;
  vertical-align:middle;
}
div img {
  opacity:0.5
}
div {
  background:url(https://i.sstatic.net/C8nGL.png);
  display:inline-block;
  padding:12px;
}
.dem {
  margin:15px;
  box-shadow:0 0 0 10px white;
  }
body {
  background:#333;
  }
<div>
  <img src="http://lorempixel.com/140/100/people/9" />
</div>
<img src="http://lorempixel.com/140/100/people/9" class="dem"/>
<img src="https://i.sstatic.net/C8nGL.png" />

snippet screenshot

Comments

0
#oval-shape {
    width: 18%;
    height: 209px; 
    background: blue; 
    -moz-border-radius: 100px / 50px; 
    -webkit-border-radius: 50%/* border-radius: 100px / 50px; */
    border-radius: 50%;

}

try with different height and width according to you shape. I think this will work

3 Comments

you should delete this answer
@GCyrillus Can u suggest me please y should i delete this answer and what is the best way to answer?
You should indent the code you put in answser (for readability) and explain a little what it is about, so answer has some value. As it is , you have been lucky that no one downvoted it :) I just edited your answer for the code part, and you can notice easy what it is about and that there is something wrong with the syntaxe .. last 2 lines won't be of any use ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.