Wrapping Divs encircling a Round Div

Looking for advice on how to place 5 div elements around a circular div.

Here's the code I currently have:

.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'm aiming for my layout to resemble the following:

https://i.sstatic.net/KLYfu.jpg

Appreciate any help. Thank you.

Answer №1

To achieve the desired layout, it is important to position the smaller circles in relation to the larger one.

An effective way to center them is by utilizing the calc() function.

Next, a sequential set of transformations is applied to each small circle. This involves moving them to the outer edge and then rotating each by 72 degrees (1/5th of 360 degrees) around the central circle. If you are using tools like SASS, this repetitive transformation step can be automated with 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>

Answer №2

To position the small circles, you can use position: absolute; and adjust the values of top, left, right, or bottom to place them where desired.

It is recommended to use percentages (%) for positioning to ensure responsiveness. However, if the size of the big circle is fixed, you can also set the position using pixels (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>

Answer №3

    <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>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Understanding the integration of sass with webpack in an Angular 4 project

Is it possible to reference a sass file instead of a css file directly in the index.html? If so, how does webpack compile the sass into a css file? Additionally, what is the most effective way to bundle the sass file when building the application? The ve ...

Clear out all current cookies

I utilized the following JavaScript code to generate a pop-up window on the website that would only appear once. However, my client now wants to launch a new promotion and I am attempting to remove existing cookies so that the pop-up window displays again ...

Exploring the possibilities of DOM events within nodeJS and express

Does anyone have experience catching a DOM event with NodeJS and Express? I've been looking into the "socket.io" module but am having trouble using it properly. My goal is to run some code whenever the content of a "file input" changes in the DOM. & ...

Attempting to incorporate a JavaScript script into my Java Maven project

Currently, I am incorporating an Ajax request into my Java Maven project. This project follows the MVC pattern, with the view being rendered in HTML and the model and controller being implemented in Java. My goal is to retrieve data from a data set contain ...

Instructions for applying a border style to a dynamically generated table using jQuery

I'm currently working on adding CSS to a table that is generated dynamically when a button is clicked. The function that is triggered on the click event includes the following jQuery code to create the dynamic rows: $("#employeDetail").append('& ...

Sustaining the hover effect background color when hovering over submenu options

I am currently working on a navigation menu that includes list items a, b, c, d, e, f. One issue I am facing is when a user hovers over the list item d, the submenu items like d1, d2, d3, d4, and d5 appear within the d section. However, the background col ...

Is there a way to trigger a "click" on a webpage without physically clicking? So that I can preview the response message before actually clicking

Is it possible to generate a "mock" request to a server through a website in order to examine the response before sending the actual request? Let me clarify with an example: if I were to click on a button on a website, it displays a certain message. I am ...

Evaluating the criteria and presenting two distinct notifications with setCustomValidity

When validating text fields in an HTML form, I am looking to check two conditions. Currently, the code below checks if the phone number entered is in the correct format and displays a message 'Enter a valid mobile number' if it is incorrect using ...

Having trouble getting CSS animation to work on Mozilla using mozAnimationName?

<style> @keyframes shake { 0% { -moz-transform:scale(0);opacity:0; } 25% { -moz-transform:scale(1.3);opacity:1; } 50% { -moz-transform:scale(0.7);opacity:1; } 75% { -moz-transform:scale(2); ...

Dealing with POST redirection and retrieving parameters in Next.js

In a typical scenario, browsers send GET requests and servers return pages. However, in my case, I am making requests to a remote server and need to receive responses. The issue is that the server redirects me back to my page via a POST request with some d ...

The received reply does not align with the set parameter configuration:

Encountering an issue with Angular $resource: error description Error: error:badcfg Response does not match configured parameter: Error in resource configuration for action `array`. Expected response to contain an object but got an {2} Initialization of ...

Avoid Repeating an Animation with Jquery

When you continuously press a button that triggers a function with animation, the function is called multiple times and the animation plays one after another. How can you prevent the function from being triggered while the animation is still in progress? ...

Execute an AJAX request in JavaScript without using string concatenation

On my webpage, users input code in a programming language which can be over 2000 characters long and include any characters. When they press the send button, the code is sent to a server-side script file using JavaScript AJAX. Currently, I am using the fo ...

Encountering a Meteor issue during the installation of npm packages

When attempting to install cheerio through npm, I encountered a specific error message. Error: Can't set DOCTYPE here. (Meteor sets <!DOCTYPE html> for you) - line 1, file Similarly, when trying to use jsdom, I faced a parse error. Currently ...

Ways to conceal a div element with the help of a radio button

I'm trying to hide a whole field that is represented by a div id, but I'm having trouble getting it to work. Oddly enough, when I used a dropdown list and select option, it worked fine. Here's the code snippet: HTML: <div class="form-gr ...

The search bar effortlessly slides into view on the navigation bar as I scroll down using Bootstrap 4

Is it possible to create a hidden searchbar within a navbar that only appears when scrolling down, and if so, can I set the timing for when it appears after scrolling? ...

Having difficulty with CSS animation and background issues

I can't seem to get my rotating background to work using CSS keyframe animation. I've tried different things but can't figure out what's going wrong. Below is my code: .main-header { width: 100%; Height: 128px; } .main-header, ...

The server is not responding to the Ajax call

In my Javascript file, the code snippet below is what I'm working with: $.getJSON("/ProductMatrix/LocationList/" + $("#categoryTypeFilter > option:selected").attr("value"), function (data) { var items = "<option> Default </option&g ...

What are some tips for dynamically updating the Toolbar in React Material UI through programming?

One of the challenges I'm facing is with a Material UI Select component that I use to navigate between several pages. While this component is shared across all pages, I have specific Toolbar components on certain pages that I would like to programmati ...

Ensuring the functionality of WebAPI endpoints through JavaScript

Is there a foolproof way to ensure that your WebAPI controller routes stay aligned with the client-side requirements? Let's say you have a BooksController for your WebAPI. On the client side, a method is invoked by calling the endpoint like this: $. ...