The concept
- Imagine a large circle, represented by a div with the CSS properties
border-radius: 100%
and width:
greater than or equal to its containing element.
- Conceal half of the circle from view at the top.
- Horizontally align the circle at the center of its container.
Adjust the size (width
, height
) and positioning (top
, left
) relative to its containing element using percentage units and apply position: absolute
. Ensure that the circle is placed inside a container with position: relative
.
Visual representation
The red portion represents the viewport (what is visible):
https://i.sstatic.net/OqkvS.png
Demonstration
An example showcasing a responsive design approach:
.container {
display: grid;
place-content: center;
overflow: hidden;
position: relative;
min-height: 100vh;
min-width: 100vw;
}
.gradient {
background: linear-gradient(180deg, #e9fff8 59.5%, #a7edd4);
border-radius: 100%;
height: 100%;
width: 100%;
top: -50%;
position: absolute;
/* Move it behind other elements */
z-index: -1;
}
@media screen and (max-width: 480px) {
.gradient {
width: 200%;
left: -50%;
}
}
/* Styles below are irrelevant to the main functionality */
* {
margin: 0;
}
<div class="container">
<div class="gradient"></div>
<div class="content">
Lorem ipsum dolor sit amet.
</div>
</div>