I need help understanding clip-path CSS property in order to make my version of a clipped circle below…
More like the design version:
If you can see on the grey background, my circle appears a lot larger and less round when it’s clipped.
What can I do to make a more round circle? My ideas were:
- Use clip-path as in the snippet below
- Use a pseudo
:after
element or a right border with radius - Cut a circle image from photoshop and use it as a background image.
Preferably, I’d like to avoid using a background image. However, I need to keep responsiveness in mind as the circle cannot change shapes drastically as we resize the window.
Is clip-path the right way to go? Can someone suggest a simpler and elegant solution with another way using CSS?
Thank you in advance, here’s a snippet I wrote that illustrates how I clipped the “green/blue” background:
.page-banner {
background: grey;
width: 100%;
height: 300px;
background-position: top;
overflow: hidden;
}
.page-banner-text {
position: absolute;
background: #00525d8a;
padding-left: 100px;
width: 60%;
/* adjustments to snippet */
top: 10px;
left: 10px;
height: 300px;
/* this is the code for circle */
clip-path: circle(560px at left);
padding-right: 250px;
}
<div class="page-banner">
<div class="container">
<div class="page-banner-text">
<h1 class="block-title">Programs For Adults</h1>
<p>Programs to help children with disabilities in Western MA at all ages and levels of need.</p>
<div id="banner-donate-button"><a href="#" class="" target="_self" title="Donate">DONATE</a></div>
</div>
</div>
</div>
3
Answers
You could simply use
border-radius
equal to half the element’sheight
andwidth
position: relative
with negativetop
andleft
valuesoverflow: hidden
A simple implementation:
Per my comment, instead of using clip path to create your D (which is not supported very well), why not use border radius on your div.
The only problem with it being responsive though is that as the screen gets wider, the D gets flatter (as the radius extends), but you can combat this by adding a max width and height to the circle div
To anyone looking to solve this with the
clip-path
property, you have a bit more control with theellipse
clip path. Using the code provided by the OP, I replaced circle with ellipse, and switched to percentages to allow for a slightly better responsive feel.clip-path:ellipse(67% 100% at 8% 50%);
The first two numbers represent the height and width of the ellipse. The larger the first number, the wider the visible area is. The larger the second number, the wider the height. We’re aiming for a D shape, so by adjusting the first number, we can make the D more or less prominent.
This is where the second two numbers, the positioning, comes into play.
at 50% 50%
centers it. By adjusting the first number, the X positioning, we can move it over where need fit . After playing around with the numbers, you should be able to get the D exactly how you’d like.