Trying to align three circles touching each other has been a challenge for me. Although I have successfully managed to make two touch, the third one remains elusive. How can I ensure that all three circles are in contact with each other, especially when the radius of each circle is subject to change?
I had considered using absolute positioning, but I'm uncertain about how it would interact with dynamic radii.
If anyone has suggestions or guidance on achieving this, I would greatly appreciate it. https://i.sstatic.net/1ywxT.jpg
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Static Template</title>
<style>
.circle-diagram {
height: 100%;
min-height: 190px;
}
.circle-diagram .solar-grid-wrapper {
display: flex;
}
.circle-diagram .yellow-circle,
.circle-diagram .yellow-circle-shadow {
border-radius: 50%;
overflow: hidden;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
color: #fff;
font-size: 12px;
width: 130px;
height: 130px;
background-color: #feda02;
}
.circle-diagram .green-circle,
.circle-diagram .green-circle-shadow {
border-radius: 50%;
overflow: hidden;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
color: #fff;
font-size: 12px;
width: 91.05px;
height: 91.05px;
background-color: #25dc8a;
left: 124px;
top: 15px;
}
.circle-diagram .blue-circle,
.circle-diagram .blue-circle-shadow {
border-radius: 50%;
overflow: hidden;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
color: #fff;
font-size: 12px;
width: 119.8px;
height: 119.8px;
background: #3d7ff9;
left: 108px;
top: 106px;
}
.circle-diagram .symbol {
height: 15px;
margin-bottom: 8px;
}
.circle-diagram .value {
z-index: 10;
opacity: 1;
font-weight: 550;
}
#randomButton {
margin-top: 60px;
border: 1px solid black;
background: #3d7ff9;
padding: 10px;
}
</style>
</head>
<body>
<div class="circle-diagram">
<div class="solar-grid-wrapper">
<div
class="yellow-circle"
id="circle1"
style="width: 150px; height: 150px;"
>
<div class="value">Cool text 1</div>
</div>
<div
class="blue-circle"
id="circle2"
style="width: 160px; height: 160px;"
>
<div class="value">Cool text 2</div>
</div>
</div>
<div
class="green-circle"
id="circle3"
style="width: 222px; height: 222px;"
>
<div class="value">Cool text 3</div>
</div>
</div>
<button id="randomButton">Random Width</button>
</body>
<script>
document.getElementById("randomButton").addEventListener(
"click",
function() {
function random(min, max) {
return Math.round(Math.random() * Math.abs(max - min) + min);
}
const randomNumber1 = random(150, 220);
const randomNumber2 = random(150, 220);
const randomNumber3 = random(150, 220);
document.getElementById("circle1").style.width = `${randomNumber1}px`;
document.getElementById("circle1").style.height = `${randomNumber1}px`;
document.getElementById("circle2").style.width = `${randomNumber2}px`;
document.getElementById("circle2").style.height = `${randomNumber2}px`;
document.getElementById("circle3").style.width = `${randomNumber3}px`;
document.getElementById("circle3").style.height = `${randomNumber3}px`;
},
false
);
</script>
</html>