I need to achieve an effect like in this demo.
But the code I used there is too specific and not very clean. As you can see I have used quite a lot of elements and also some transforms with very specific angle calculations.
Is there a way for me to create this shape, keep it responsive but in a cleaner way? Please note that I don't want just half a circle, but a very specific angle that I could adapt. I mean the circle could be more or less inside the rectangle, so the angle of the arc would be more or less big.
CSS:
.rectangle {
background-color: white;
width:200px;
height:200px;
border:solid 1px navy;
}
.circle {
position: relative;
width: 70px; height: 70px;
border-radius: 50%;
background: white;
margin-top:calc(50% - 35px);
margin-left:calc(100% - 50px);
}
.arc {
overflow: hidden;
position: absolute;
top: -1px; right: 50%; bottom: 50%; left: -1px;
transform-origin: 100% 100%;
transform: rotate(115deg);
}
.arc:before {
box-sizing: border-box;
display: block;
border: solid 1px navy;
width: 200%; height: 200%;
border-radius: 50%;
content: '';
}
.arc2 {
overflow: hidden;
position: absolute;
top: -1px; right: 50%; bottom: 50%; left: -1px;
transform-origin: 100% 100%;
transform: rotate(155deg);
}
.arc2:before {
box-sizing: border-box;
display: block;
border: solid 1px navy;
width: 200%; height: 200%;
border-radius: 50%;
content: '';
}
HTML:
<div class='rectangle'>
<div class='circle'>
<div class='arc'></div>
<div class='arc2'></div>
</div>
</div>
Points to Note:
- I cannot use z-index, it was my first solution but it causes other problems.
- The height of the rectangle can change and so I'd need it to be responsive but the height of the circle should stay the same even if the height of the container gets bigger
- I can use SVG if that is an option.