Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Divs around a circular Div

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

enter image description here

Thank you.

like image 907
Agent69 Avatar asked Sep 11 '17 13:09

Agent69


2 Answers

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>
like image 153
Patrick Kunka Avatar answered Nov 03 '22 11:11

Patrick Kunka


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>
like image 26
Troyer Avatar answered Nov 03 '22 12:11

Troyer