Reputation: 678
I'm trying to put 5 div around a circle div, how can I achieve it ?
This is my code so far :
.main{
border: 2px dotted #000000;
border-radius: 50%;
width: 500px;
height: 500px;
}
.cirlce1{
height: 50px;
width: 50px;
border: 2px dotted #000000;
border-radius: 50%;
top: 50px;
}
.cirlce2{
height: 50px;
width: 50px;
border: 2px dotted #000000;
border-radius: 50%;
top: 50px;
}
<div class="main">
<div class="cirlce1"></div>
<div class="cirlce2"></div>
</div>
I want my output to be like
Thank you.
Upvotes: 9
Views: 10200
Reputation: 18
<style type="text/css">
.main{
border: 2px dotted #000000;
border-radius: 50%;
width: 500px;
height: 500px;
}
.cirlce1{
height: 50px;
width: 50px;
border: 2px dotted #000000;
border-radius: 50%;
top: 50px;
margin-top: 75px;
}
.cirlce2{
height: 50px;
width: 50px;
border: 2px dotted #000000;
border-radius: 50%;
top: 50px;
margin-top: 240px;
}
.cirlce3{
height: 50px;
width: 50px;
border: 2px dotted #000000;
border-radius: 50%;
margin-bottom: 10px;
margin-left: 400px;
}
.cirlce4{
height: 50px;
width: 50px;
border: 2px dotted #000000;
border-radius: 50%;
top: 50px;
margin-bottom: 750px;
margin-left: 250px;
}
.cirlce5{
height: 50px;
width: 50px;
border: 2px dotted #000000;
border-radius: 50%;
margin-left: 450px;
margin-top: -1200px;
}
</style>
<div class="main">
<div class="cirlce1"></div>
<div class="cirlce2"></div>
<div class="cirlce3"></div>
<div class="cirlce4"></div>
<div class="cirlce5"></div>
</div>
Upvotes: 0
Reputation: 1048
The key is to position the small circles absolutely in relation to the big one.
You can then center them using calc()
.
Finally a series of transforms is applied to each small circle, moving them to the outside edge, then rotating each one around the large circle by 1/5th of 360deg (72deg). If you're using a preprocessor such as SASS, this final step could be done using a loop.
.main {
position: relative;
border: 2px dotted #000000;
border-radius: 50%;
width: 500px;
height: 500px;
}
.circle {
position: absolute;
left: calc(50% - 25px);
top: calc(50% - 25px);
height: 50px;
width: 50px;
border: 2px dotted #000000;
border-radius: 50%;
}
.circle:nth-child(1) {
transform: translateX(250px);
}
.circle:nth-child(2) {
transform: rotate(72deg) translateX(250px);
}
.circle:nth-child(3) {
transform: rotate(144deg) translateX(250px);
}
.circle:nth-child(4) {
transform: rotate(216deg) translateX(250px);
}
.circle:nth-child(5) {
transform: rotate(288deg) translateX(250px);
}
<div class="main">
<div class="circle"></div>
<div class="circle"></div>
<div class="circle"></div>
<div class="circle"></div>
<div class="circle"></div>
</div>
Upvotes: 21
Reputation: 7013
You can set the position of the small circles as position: absolute;
and then play with top
, left
, right
or bottom
for placing them on the desired place.
I recommend you to use %
for setting the position so it will be responsive, but in the case the big circle size is static you can just set the position with px
.
.main{
border: 2px dotted #000000;
border-radius: 50%;
width: 500px;
height: 500px;
}
.cirlce1{
position: absolute;
height: 50px;
width: 50px;
border: 2px dotted #000000;
border-radius: 50%;
top: 50%;
}
.cirlce2{
position: absolute;
height: 50px;
width: 50px;
border: 2px dotted #000000;
border-radius: 50%;
left: 50%;
}
<div class="main">
<div class="cirlce1"></div>
<div class="cirlce2"></div>
</div>
Upvotes: 7