0

I need to make a circular navigation menu similar to the link below, shape-wise. I need to have six buttons on mine. The issue is, I need to do this using only CSS and HTML. I have made various attempts at this, but I am at a lost as to how to achieve it. I have tried it with transforms, absolute positioning, and other ways... but I'm not getting decent results. If someone could help me design the buttons, I would greatly appreciate it. I have included my container divs for reference.

Example Similar Shape

.circle-main {
  background-color: rgba(255, 190, 0, 1.00);
  border-radius: 50%;
  height: 400px;
  margin: 0 auto;
  width: 400px;
}

.circle-center {
  background-color: rgba(255, 255, 255, 1.00);
  border-radius: 50%;
  height: 250px;
  margin: 75px auto 0px 75px;
  position: absolute;
  width: 250px;
}
<div class="circle-container">
  <div class="circle-main">
    <div class="circle-center"></div>
  </div>
</div>
Penny Liu
  • 15,447
  • 5
  • 79
  • 98
  • I made a thing, but I got stuck too. Maybe this will give you some ideas though... https://jsfiddle.net/vuckjgd3/2/ – Joseph Dykstra Sep 26 '18 at 02:04
  • See here https://css-tricks.com/set-text-on-a-circle/ how to do it. It's a lot of typing though only using HTML and CSS – Gerard Sep 26 '18 at 03:16
  • SVG is the simplest option - https://stackoverflow.com/questions/27943053/how-to-create-a-circle-with-links-on-border-side – Paulie_D Sep 26 '18 at 11:18

2 Answers2

0

This can be achieved by CSS Transform:

html,
body {
  font-size: 20px;
  background-color: white;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  list-style: none;
  position: relative;
}

.nav-wrapper {
  width: 26em;
  height: 26em;
  overflow: hidden;
  position: fixed;
  z-index: 10;
  top: 0;
  left: 50%;
  border-radius: 50%;
  margin-left: -13em;
  -webkit-transform: scale(0.1);
          transform: scale(0.1);
  pointer-events: none;
  transition: all 0.3s ease;
  border-radius: 50%;
  pointer-events: auto;
  -webkit-transform: scale(1);
          transform: scale(1);
}
.nav-wrapper li {
  position: absolute;
  width: 10em;
  height: 10em;
  border: 1px solid white;
  -webkit-transform-origin: 100% 100%;
          transform-origin: 100% 100%;
  overflow: hidden;
  left: 50%;
  top: 50%;
  margin-top: -1em;
  margin-left: -6em;
  transition: border 0.3s ease;
}
.nav-wrapper li:first-child {
  -webkit-transform: rotate(0deg) skew(45deg);
          transform: rotate(0deg) skew(45deg);
}
.nav-wrapper li:nth-child(2) {
  -webkit-transform: rotate(45deg) skew(45deg);
          transform: rotate(45deg) skew(45deg);
}
.nav-wrapper li:nth-child(3) {
  -webkit-transform: rotate(90deg) skew(45deg);
          transform: rotate(90deg) skew(45deg);
}
.nav-wrapper li:nth-child(4) {
  -webkit-transform: rotate(135deg) skew(45deg);
          transform: rotate(135deg) skew(45deg);
}
.nav-wrapper li:nth-child(5) {
  -webkit-transform: rotate(180deg) skew(45deg);
          transform: rotate(180deg) skew(45deg);
}
.nav-wrapper li:nth-child(6) {
  -webkit-transform: rotate(225deg) skew(45deg);
          transform: rotate(225deg) skew(45deg);
}
.nav-wrapper li:nth-child(7) {
  -webkit-transform: rotate(270deg) skew(45deg);
          transform: rotate(270deg) skew(45deg);
}
.nav-wrapper li:nth-child(8) {
  -webkit-transform: rotate(315deg) skew(45deg);
          transform: rotate(315deg) skew(45deg);
}
.nav-wrapper li a {
  display: block;
  height: 14.5em;
  width: 14.5em;
  position: absolute;
  bottom: -7.25em;
  right: -7.25em;
  border-radius: 50%;
  padding-top: 1.8em;
  background-color: #81d8d0;
  -webkit-transform: skew(-45deg) rotate(-45deg) scale(1);
          transform: skew(-45deg) rotate(-45deg) scale(1);
  transition: opacity 0.3s, color 0.3s;
}
.nav-wrapper li a:hover {
  background-color: #a8e4df;
}
<div class="nav-wrapper">
  <ul>
    <li><a></a></li>
    <li><a></a></li>
    <li><a></a></li>
    <li><a></a></li>
    <li><a></a></li>
    <li><a></a></li>
    <li><a></a></li>
    <li><a></a></li>
  </ul>
</div>
LouisTheTeemo
  • 218
  • 2
  • 7
0

You can create a donut chart using D3.js. (via D3 Donut Pie Chart)

// Seed data to populate the donut pie chart
var seedData = [{
  "label": "btn1",
  "value": 25,
  "link": "https://example.com/"
}, {
  "label": "btn2",
  "value": 25,
  "link": "https://example.com/"
}, {
  "label": "btn3",
  "value": 25,
  "link": "https://example.com/"
}, {
  "label": "btn4",
  "value": 25,
  "link": "https://example.com/"
}, {
  "label": "btn5",
  "value": 25,
  "link": "https://example.com/"
}, {
  "label": "btn6",
  "value": 25,
  "link": "https://example.com/"
}];

// Define size & radius of donut pie chart
var width = 450,
  height = 450,
  radius = Math.min(width, height) / 2;

// Define arc colours
var colour = d3.scaleOrdinal(d3.schemeCategory20);

// Define arc ranges
var arcText = d3.scaleOrdinal()
  .range([0, width]);

// Determine size of arcs
var arc = d3.arc()
  .innerRadius(radius - 130)
  .outerRadius(radius - 10);

// Create the donut pie chart layout
var pie = d3.pie()
  .value(function(d) {
    return d["value"];
  })
  .sort(null);

// Append SVG attributes and append g to the SVG
var svg = d3.select("#donut-chart")
  .attr("width", width)
  .attr("height", height)
  .append("g")
  .attr("transform", "translate(" + radius + "," + radius + ")");

// Define inner circle
svg.append("circle")
  .attr("cx", 0)
  .attr("cy", 0)
  .attr("r", 100)
  .attr("fill", "#fff");

// Calculate SVG paths and fill in the colours
var g = svg.selectAll(".arc")
  .data(pie(seedData))
  .enter().append("g")
  .attr("class", "arc")

  // Make each arc clickable 
  .on("click", function(d, i) {
    window.location = seedData[i].link;
  });

// Append the path to each g
g.append("path")
  .attr("d", arc)
  .attr("fill", function(d, i) {
    return colour(i);
  });

// Append text labels to each arc
g.append("text")
  .attr("transform", function(d) {
    return "translate(" + arc.centroid(d) + ")";
  })
  .attr("dy", ".35em")
  .style("text-anchor", "middle")
  .attr("fill", "#fff")
  .text(function(d, i) {
    return seedData[i].label;
  })

g.selectAll(".arc text").call(wrap, arcText.range([0, width]));

// Append text to the inner circle
svg.append("text")
  .attr("dy", "-0.5em")
  .style("text-anchor", "middle")
  .attr("class", "inner-circle")
  .attr("fill", "#36454f")
  .text(function(d) {
    return '';
  });

svg.append("text")
  .attr("dy", "1.0em")
  .style("text-anchor", "middle")
  .attr("class", "inner-circle")
  .attr("fill", "#36454f")
  .text(function(d) {
    return '';
  });

// Wrap function to handle labels with longer text
function wrap(text, width) {
  text.each(function() {
    var text = d3.select(this),
      words = text.text().split(/\s+/).reverse(),
      word,
      line = [],
      lineNumber = 0,
      lineHeight = 1.1, // ems
      y = text.attr("y"),
      dy = parseFloat(text.attr("dy")),
      tspan = text.text(null).append("tspan").attr("x", 0).attr("y", y).attr("dy", dy + "em");
    console.log("tspan: " + tspan);
    while (word = words.pop()) {
      line.push(word);
      tspan.text(line.join(" "));
      if (tspan.node().getComputedTextLength() > 90) {
        line.pop();
        tspan.text(line.join(" "));
        line = [word];
        tspan = text.append("tspan").attr("x", 0).attr("y", y).attr("dy", ++lineNumber * lineHeight + dy + "em").text(word);
      }
    }
  });
}
@import url(https://fonts.googleapis.com/css?family=Roboto:400,100,100italic,300,300italic,400italic,500,500italic,700,700italic,900,900italic);
* {
  font-family: Roboto;
}

.content h1 {
  font-weight: 500;
  text-align: center;
}

svg#donut-chart {
  display: block;
  margin: 0 auto;
}

text.inner-circle {
  font-weight: 400;
  font-size: 20px;
  text-transform: uppercase;
}

.arc {
  cursor: pointer;
}

.arc:hover {
  opacity: .85;
}

.arc text {
  font-weight: 300;
  font-size: 18px;
  color: #fff;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.2.2/d3.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="content">
  <svg id="donut-chart"></svg>
</div>
Penny Liu
  • 15,447
  • 5
  • 79
  • 98