Instructions for crafting a sliced circle with CSS3 and HTML5

I need assistance creating a unique sliced circle interface where each slice can be clicked to execute different commands, similar to buttons. The design specifications for the slices are as follows:

  • 2 Circles: Main Outer circle and inner circle (half sized compared to outer circle),

  • 3 Lines over the main circle dividing the 2 circles into 12 slices. The vertical line should originate from these 3 lines.

Here is a reference image:

https://i.sstatic.net/ubRDq.png

.maincircle {
  height: 404px;
  width: 404px;
}

.slice1 {
  float: left;
  height: 200px;
  width: 200px;
  border: 1px solid #000;
  background-color: #093;
  cursor: pointer;
  border-radius: 190px 0 0 0;
  -moz-border-radius: 190px 0 0 0;
  -webkit-border-radius: 190px 0 0 0;
}

.slice1:hover {
  background-color: #6C6;
}

.slice2 {
  float: left;
  height: 200px;
  width: 200px;
  border: 1px solid #000;
  background-color: #093;
  cursor: pointer;
  -moz-border-radius: 0 190px 0 0;
  -webkit-border-radius: 0 190px 0 0;
}

.slice2:hover {
  background-color: #6C6;
}

.slice3 {
  float: left;
  height: 200px;
  width: 200px;
  border: 1px solid #000;
  background-color: #093;
  cursor: pointer;
  -moz-border-radius: 0 0 0 190px;
  -webkit-border-radius: 0 0 0 190px;
}

.slice3:hover {
  background-color: #6C6;
}

.slice4 {
  float: left;
  height: 200px;
  width: 200px;
  border: 1px solid #000;
  background-color: #093;
  cursor: pointer;
  -moz-border-radius: 0 0 190px 0;
  -webkit-border-radius: 0 0 190px 0;
}

.slice4:hover {
  background-color: #6C6;
}
<div class="maincircle">
  <div class="slice1"></div>
  <div class="slice2"></div>
  <div class="slice3"></div>
  <div class="slice4"></div>
</div>

Answer №1

Check out this quick example to see my preferred approach

DEMO http://jsfiddle.net/kevinJSkevin/XN3ZA/456/

I rely on

http://code.highcharts.com/highcharts.js
for solutions like this one. By utilizing a pie chart, you have the flexibility to customize them according to your requirements and make them behave as per your preference. It's an efficient and straightforward method.

MODIFIED

Enhanced to include multi-layer capability

$(document).ready(function() {
  Highcharts.setOptions({
    colors: ['#03ab47']
  });

  RenderPieChart('container', [
    ['first slice', 25],
    ['second slice', 35],
    ['third slice', 40]
  ]);

  function RenderPieChart(elementId, dataList) {
    new Highcharts.Chart({
      chart: {
        renderTo: elementId,
        plotBackgroundColor: null,
        plotBorderWidth: null,
        plotShadow: false
      },
      title: {
        text: 'Exploring the versatility of pie charts'
      },
      tooltip: {
        formatter: function() {

          return '<b> Incorporate an interactive feature here</b>';

        }
      },
      plotOptions: {
        pie: {
          allowPointSelect: true,
          cursor: 'pointer',
          dataLabels: {
            enabled: true,
            color: '#000000',
            connectorColor: '#000000',
            formatter: function() {
              return '<b>Make these elements clickable!</b>';
            }
          }
        }
      },
      series: [{
        type: 'pie',
        name: 'Item distribution',
        data: dataList
      }]
    });
  };
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>

<div id="container" style="min-width: 400px; height: 400px; margin: 0 auto"></div>

Answer №2

I stumbled upon this intriguing concept and decided to bring it to life using SVG:

path:hover {
  fill: blue;
}
<svg height="440px" width="440px">
  <path d="M 220 220 L 270 306.60254037844385 A 100 100 0 0 0 320 220 z" fill="green" stroke="white" onclick="alert('inner-0')" />
  <path d="M 420 220 A 200 200 0 0 1 320 393.2050807568877  L 270 306.60254037844385 A 100 100 0 0 0 320 220  z" fill="green" stroke="white" onclick="alert('outer-0')" />
  <path d="M 220 220 L 170.00000000000003 306.6025403784439 A 100 100 0 0 0 270 306.60254037844385 z" fill="green" stroke="white" onclick="alert('inner-1')" />
  <path d="M 320 393.2050807568877 A 200 200 0 0 1 120.00000000000004 393.20508075688775  L 170.00000000000003 306.6025403784439 A 100 100 0 0 0 270 306.60254037844385  z" fill="green" stroke="white" onclick="alert('outer-1')" />
  <path d="M 220 220 L 120 220 A 100 100 0 0 0 170.00000000000003 306.6025403784439 z" fill="green" stroke="white" onclick="alert('inner-2')" />
  <path d="M 120.00000000000004 393.20508075688775 A 200 200 0 0 1 20 220.00000000000003  L 120 220 A 100 100 0 0 0 170.00000000000003 306.6025403784439  z" fill="green" stroke="white" onclick="alert('outer-2')" />
  <path d="M 220 220 L 169.99999999999994 133.39745962155615 A 100 100 0 0 0 120 220 z" fill="green" stroke="white" onclick="alert('inner-3')" />
  <path d="M 20 220.00000000000003 A 200 200 0 0 1 119.99999999999991 46.79491924311233  L 169.99999999999994 133.39745962155615 A 100 100 0 0 0 120 220  z" fill="green" stroke="white" onclick="alert('outer-3')" />
  <path d="M 220 220 L 269.99999999999994 133.3974596215561 A 100 100 0 0 0 169.99999999999994 133.39745962155615 z" fill="green" stroke="white" onclick="alert('inner-4')" />
  <path d="M 119.99999999999991 46.79491924311233 A 200 200 0 0 1 319.9999999999999 46.79491924311219  L 269.99999999999994 133.3974596215561 A 100 100 0 0 0 169.99999999999994 133.39745962155615  z" fill="green" stroke="white" onclick="alert('outer-4')"
  />
  <path d="M 220 220 L 320 219.99999999999997 A 100 100 0 0 0 269.99999999999994 133.3974596215561 z" fill="green" stroke="white" onclick="alert('inner-5')" />
  <path d="M 319.9999999999999 46.79491924311219 A 200 200 0 0 1 420 219.99999999999994  L 320 219.99999999999997 A 100 100 0 0 0 269.99999999999994 133.3974596215561  z" fill="green" stroke="white" onclick="alert('outer-5')" />
</svg>

http://jsfiddle.net/u2h4J/2/

If you're curious about the process, here's the somewhat messy code I used to generate it:

var RADIUS = 200;
var PADDING = 20;
var SLICES = 6;

var svg = "";

for (var i = 0; i < SLICES; i++) {
  var p1 = {
    x: Math.cos(Math.PI * 2 / SLICES * i) * RADIUS + RADIUS + PADDING,
    y: Math.sin(Math.PI * 2 / SLICES * i) * RADIUS + RADIUS + PADDING
  };

  var p2 = {
    x: Math.cos(Math.PI * 2 / SLICES * (i + 1)) * RADIUS + RADIUS + PADDING,
    y: Math.sin(Math.PI * 2 / SLICES * (i + 1)) * RADIUS + RADIUS + PADDING
  };

  var p4 = {
    x: Math.cos(Math.PI * 2 / SLICES * i) * (RADIUS / 2) + RADIUS + PADDING,
    y: Math.sin(Math.PI * 2 / SLICES * i) * (RADIUS / 2) + RADIUS + PADDING
  };

  var p3 = {
    x: Math.cos(Math.PI * 2 / SLICES * (i + 1)) * (RADIUS / 2) + RADIUS + PADDING,
    y: Math.sin(Math.PI * 2 / SLICES * (i + 1)) * (RADIUS / 2) + RADIUS + PADDING
  };


  svg += "<path d='M " + (RADIUS + PADDING) + " " + (RADIUS + PADDING) + " L " + p3.x + " " + p3.y + " A " + (RADIUS / 2) + " " + (RADIUS / 2) + " 0 0 0 " + p4.x + " " + p4.y + " z' fill='green' stroke='white' onclick='alert(\"inner-" + i + "\")'/>";

  svg += "<path d='M " + p1.x + " " + p1.y + " A " + RADIUS + " " + RADIUS + " 0 0 1 " + p2.x + " " + p2.y + "  L " + p3.x + " " + p3.y + " A " + RADIUS / 2 + " " + RADIUS / 2 + " 0 0 0 " + p4.x + " " + p4.y + "  z' fill='green' stroke='white' onclick='alert(\"outer-" + i + "\")'/>";
}

svg = "<svg height='" + (RADIUS * 2 + PADDING * 2) + "px' width='" + (RADIUS * 2 + PADDING * 2) + "px'>" + svg + "</svg>";

$("body").append(svg);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>

http://jsfiddle.net/t3pLn/1/

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

After the user refreshes the page, the PHP validation error message fails to appear

There is an issue with validation on the input fields. For example, if I enter only one character instead of the required 2-25 characters for the username, an error message appears. The problem persists even after refreshing the page. How can I clear the v ...

Ways to utilize JavaScript to identify if a flash is launching in a separate tab

On my website, I have embedded a third-party flash player using an iframe. Whenever a user clicks on a specific area within the flash player, a new tab is opened in the browser. I am trying to track the frequency of this occurrence. However, I have encoun ...

Deactivate click events in the container div

Here is the html code snippet that I am working with: <div class="parent" ng-click="ParentClick()"> . . . <div class="child" ng-click="ChildClick()"> Some Text </div> </div> When clicking on Som ...

TS2345: The argument provided, which is of type 'Event', cannot be assigned to the parameter expected, which is of type 'HtmlInputEvent'

I am facing an issue while trying to upload a file, and I could use some assistance in resolving it. Angular-----Error: src/app/admin/producto/create-producto-dialog.html:38:47 - error TS2345: Argument of type 'Event' is not assignable to parame ...

Combining MarkDown elements into a DIV or a custom HTML tag

I have utilized the Jeykll tool to convert mark down content into HTML. I am looking to group the following mark down elements within a div element or another custom HTML tag. Markdown #Multiple Axis {:.title} Different types of data can be vis ...

The mysterious case of the vanishing close button on Curator.io's mobile

Currently, I am using curator.io aggregator to showcase my Instagram feed on the website. An issue arises when switching to mobile view as the close button (class="crt-close") disappears. You can see an example of this here: To replicate the pr ...

Verify if the JSON attribute is empty

My input contains the following: { "headers": { ... }, "body": { "RequestInfo": { ... , "Identificator": null } } <filter regex="false" source="boolean($ctx:Identificator)"> - check if it exists (even when it's ...

Is there a way to efficiently process multipart/formdata, application/json, and text/plain within a single Express handler?

Operating an express demo server that mirrors the client's POST requests back to it is a part of an educational practice. In this exercise, the client makes a POST request using the fetch API, like so: fetch('http://localhost:5000/', { m ...

What is the best way to retrieve a style property from a <style> tag using JavaScript?

Is there a way to retrieve CSS properties set in the <style> tag in JavaScript, rather than just those set in the element's style attribute? For example: <style> div{background:red;} </style> How can I access these styles, such ...

What is the method for arranging objects in AngularJS using a custom sorting sequence?

I would like to display an array of object's properties in a custom sorted order. Here is the initial array: $scope.weekDays = [ { "day" : "TUESDAY", "count": 10 }, { ...

The button is unable to contain all the text, causing it to spill out instead of wrapping to

Need help with creating an HTML button that opens a link. The button consists of a title and a short description, but when the description is too long, it overflows outside the button. Currently implementing bootstrap and jquery. Code: body { backgr ...

Understanding the syntax for matching files and paths in Node/JavaScript using glob, including the use of wild

I stumbled upon http://gruntjs.com/configuring-tasks#globbing-patterns and found it to be the most useful reference so far. I have come across the following statement multiple times: For more on glob pattern syntax, see the node-glob and minimatch docu ...

Transferring HTML information to Flask

I'm struggling with passing a value from a text box in a web application to a Flask application. Despite my efforts, the request object in Flask does not seem to contain the data I need. Can anyone provide assistance with this issue? Below are the rel ...

Is there a way to retrieve a particular object from the state and access one of its elements?

I have a component called Tweets.js: import React, {Component} from "react"; export default class Tweets extends Component { constructor(props) { super(props); this.state = {tweets: [], users: []}; } componentDi ...

Saving data from the Viewbag into a jQuery array or object on the client side

Imagine this scenario: I have a dynamic object called ViewBag, which is essentially a list filled with some results; Scenario 1: User 1 enters and populates the ViewBag.Products object with a list of 50 items; Scenario 2: User 2 enters and fills t ...

I am curious if there is a feature in intro.js that allows for the highlighting of text or images to

I am having trouble getting intro.js to work with Ionic 4 as the highlighted text is not showing up view image here This is how I implemented the code in Angular 7: intro() { let intro = introJs.introJs(); intro.setOptions({ exitOnOverlayClick: false, ...

Issues with Angular's :has selector functionality are causing it to perform inaccur

I've been attempting to make the has selector function properly with angular. Here's my HTML code: <ul class="check-list no-bullet-points mb-0"> <ng-container *ngFor="let item of checkList.items"> &l ...

Unable to reset session with JavaScript on JSP page

Created a session from the login.jsp page using a servlet String msg = ""; HttpSession sess = request.getSession(); // if(sess != null) //sess.invalidate(); if (sess.getId() != null) { sess.setAttribute("uname", ...

How can I customize the visibility toggles for the password input field in Angular Material?

Currently immersed in the Angular 15 migration process... Today, I encountered an issue with a password input that displays two eyes the first time something is entered in the field. The HTML code for this is as follows: <mat-form-field appearance=&qu ...

Display a single unique value in the dropdown menu when there are duplicate options

Hey there, I'm currently working on retrieving printer information based on their location. If I have multiple printers at the same location, I would like to only display that location once in the dropdown menu. I am aware that this can be resolved at ...