Troubles with CSS Child Hover, Rotation, and Clipping in Pie Chart styling

The issue I am facing is with a 3-section pie chart where all sections look virtually identical. However, the :hover effect does not trigger on the first section, but it works on the other two.

Each element has an equal number of overlapping parent divs, so that should not be causing the problem. It seems like a random and obscure bug related to a feature, but I am unsure how to fix it. This behavior has been observed in Chrome, Firefox, and Internet Explorer.

(I am aware that the top section is poorly positioned, I removed some extra fixes for simplicity to highlight the bug)

If you want to check out the full code, here is the link: codepen.io

Below is the HTML:

<div class="colors">
            <div class="clip" id="color1"><div class="section" id="color1Actual"></div></div>
            <div class="clip" id="color2"><div class="section" id="color2Actual"></div></div>
            <div class="clip" id="color3"><div class="section" id="color3Actual"></div></div>
        </div>

And here is the CSS:

.colors {
    width: 131px;
    height: 131px;
    margin-top: 32%;
    margin-left: 12%;
    border-radius: 50%;
}

.colors div {
    position: absolute;
    height: 132px;
    width: 132px;
    border-radius: 50%;
}

#color1Actual {
    background-color: #ADD8E6;
    transform: rotate(60deg);
}

#color1, #color1Actual {
    clip: rect(0px, 132px, 66px, 0px);
}

#color1Actual:hover {
    background-color: #0000FF;
}

#color2Actual {
    background-color: #ADD8E6;
    transform: rotate(60deg);
}

#color2, #color2Actual {
    clip: rect(0px, 132px, 132px, 66px);
}

#color2Actual:hover {
    background-color: #0000FF;
}

#color3Actual {
    background-color: #FFFFE0;
    transform: rotate(-60deg);
}

#color3, #color3Actual {
    clip: rect(0px, 66px, 132px, 0px);
}

#color3Actual:hover {
    background-color: #FFFF00;
}

Answer №1

To achieve this effect, make sure to utilize the z-index property.

.colors {
    width: 131px;
    height: 131px;
    margin-top: 12%;
    margin-left: 12%;
    border-radius: 50%;
}

.colors div {
    position: absolute;
    height: 132px;
    width: 132px;
    border-radius: 50%;
}

#color1Actual {
    background-color: #ADD8E6;
    transform: rotate(60deg);
    z-index: 1;
}

#color1, #color1Actual {
    clip: rect(0px, 132px, 66px, 0px);
}

#color1Actual:hover {
    background-color: #0000FF;
}

#color2Actual {
    background-color: #ADD8E6;
    transform: rotate(60deg);
    z-index: 2;
}

#color2, #color2Actual {
    clip: rect(0px, 132px, 132px, 66px);
}

#color2Actual:hover {
    background-color: #0000FF;
}

#color3Actual {
    background-color: #FFFFE0;
    transform: rotate(-60deg);
    z-index: 3;
}

#color3, #color3Actual {
    clip: rect(0px, 66px, 132px, 0px);
}

#color3Actual:hover {
    background-color: #FFFF00;
}
<div class="colors">
            <div class="clip" id="color1"><div class="section" id="color1Actual"></div></div>
            <div class="clip" id="color2"><div class="section" id="color2Actual"></div></div>
            <div class="clip" id="color3"><div class="section" id="color3Actual"></div></div>
        </div>

Answer №2

To fix the issue of overlapping divs, simply apply a z-index to the elements and they will display properly :)

.colors {
  width: 131px;
  height: 131px;
  margin-top: 32%;
  margin-left: 12%;
  border-radius: 50%;
}
.colors div {
  position: absolute;
  height: 132px;
  width: 132px;
  border-radius: 50%;
}
#color1Actual {
  background-color: #ADD8E6;
  transform: rotate(60deg);
  z-index:1;
}
#color1,
#color1Actual {
  clip: rect(0px, 132px, 66px, 0px);
}
#color1Actual:hover {
  background-color: #0000FF;
}
#color2Actual {
  background-color: #ADD8E6;
  transform: rotate(60deg);
}
#color2,
#color2Actual {
  clip: rect(0px, 132px, 132px, 66px);
}
#color2Actual:hover {
  background-color: #0000FF;
}
#color3Actual {
  background-color: #FFFFE0;
  transform: rotate(-60deg);
}
#color3,
#color3Actual {
  clip: rect(0px, 66px, 132px, 0px);
}
#color3Actual:hover {
  background-color: #FFFF00;
}
<div class="colors">
  <div class="clip" id="color1">
    <div class="section" id="color1Actual"></div>
  </div>
  <div class="clip" id="color2">
    <div class="section" id="color2Actual"></div>
  </div>
  <div class="clip" id="color3">
    <div class="section" id="color3Actual"></div>
  </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

Acquire HTML information using the Robot framework and xpath techniques

My first task is to visit the website www.google.de. I aim to extract the word Deutschland from this section of the HTML code: <div class="logo-subtext">Deutschland</div> Since the id in this div class is not available, I must utilize xpath. ...

Differences in Print Layout Between Chrome and Firefox when Viewing a PHP Website

I have been working on creating a print command to print a specific div, and I have managed to successfully run the print command using default methods like CTRL + P and also with a button click. The Issue: However, I have encountered a problem where the ...

How can I toggle the visibility of a div based on whether a variable is defined or not?

How can I display a specific div on my webpage only when certain variables in PHP pull out a specific result from a database? I attempted to use the code snippet below, but it's not working as expected. Can someone provide guidance on how to achieve ...

Uncovering a specific element within an array using knockout techniques

I am attempting to set a variable to an element within an array that holds a particular value for a property. For instance, I want to retrieve the item with an "Id" value of 15. However, my current method only retrieves the first item in the array, regar ...

What happens to the content within a <textarea> element if it is not enclosed between the opening and closing tags?

Here's a puzzling situation - I've entered the word Hello. into a <textarea>, and while I can see it on my screen, it doesn't show up between the opening and closing <textarea> tags. It may seem like a simple issue, but I'v ...

What is the best way to ensure that text fields remain hidden upon page load until the appropriate drop down option is chosen?

Is it possible to initially hide text fields and only reveal them when a specific drop down option is selected? The current JavaScript code somewhat achieves this, but I would like the input fields to remain hidden by default. <script language=" ...

The save feature becomes dysfunctional after switching to the Material-UI dependency in a React project

After integrating the Material-UI dependency into my ReactJS code, I encountered an issue where the "save" functionality no longer works properly. Previously, when editing a task in my simple Todo list app, the new name would be saved successfully. However ...

The text loader feature in THREE.js is failing to load

My first attempt at coding THREE.js resulted in a black screen when I tried to load the Text loader. Can someone help me resolve this issue? I kept getting the following error even after multiple attempts: three.module.js:38595 GET 404 (Not Found) ...

Attempting to call a nested div class in JavaScript, but experiencing issues with the updated code when implemented in

Seeking assistance. In the process of creating a nested div inside body > div > div . You can find more information in this Stack Overflow thread. Check out my JSFiddle demo here: https://jsfiddle.net/41w8gjec/6/. You can also view the nested div ...

What is the best way to define coordinates or set margins for the autoTable component in jsPdf when using React js?

While working with the jsPdf library to create a PDF in React, I am encountering an issue where I am unable to set margins for the autoTable when there are multiple tables on a single page. Below is the code snippet: import React from "react"; ...

Ways to declare a function within the events onMouseOver and onMouseOut

<div align="right" style="border:1 #FF0 solid; background-color:#999" onMouseOver="javascript: function(){this.style.backgroundColor = '#DDD';}" onMouseOut="javascript: function(){this.style.backgroundColor = '#999';}"> Register & ...

Attempting to implement image switching with hover effects and clickable regions

Hey there, I'm currently working on a fun little project and could use some guidance on how to achieve a specific effect. The website in question is [redacted], and you can view the code I've used so far at [redacted]. You'll find a code blo ...

What is the best way to dynamically adjust the width of multiple divisions in Angular?

I am currently working on an angular project to create a sorting visualizer. My goal is to generate a visual representation of an array consisting of random numbers displayed as bars using divisions. Each bar's width will correspond to the value of th ...

What is the best way to implement a CSS transition in React when the state changes, the component remounts, or it re-rend

Imagine having a React functional component with some basic state: import React, { useState } from 'react' import { makeStyles } from "@material-ui/core" export default function Cart() { const [itemNumber, setItemNumber] = useState ...

Centering the header image on the screen creates a visually appealing focal point

Looking to design a header image for my website that always stays centered. I want the image to stand out and remain in the middle even when the browser window is resized. I found an example on this website that achieves this effortlessly. ...

HTML allows for the creation of multiple pages within a single file

How can I create nested files that have access to other files? I am working on a website where I use the following code to link different pages: <div class="topnav"> <a href="scenes/home.html">Home</a> <a h ...

Issues with appending new rows using JavaScript

I'm facing an issue with adding rows to the table using this code and I can't seem to find a solution. function add() { document.getElementById("popup").style.display = "block"; document.getElementById("add").addEventListener("click", func ...

How come the div element is not rendering the CSS styles?

What could be the reason for .header not displaying the background color and height settings? https://jsfiddle.net/f3puaeq6/1/ .header{ background-color: black; height: 300px; } ...

Is there a way to include an optional backslash in URLs using the .htaccess file without leading browsers to believe I am navigating to a subfolder?

As I update my php pages with the .htaccess file, I am facing an issue where the pages do not load properly when an optional backslash ("/") is included in the URLs. One possible solution is to use absolute URLs instead of relative ones so that CSS and J ...

What is the impact of hash urls on SEO?

Looking for back button support options? Check out some recommended plugins here. However, considering that the page loads via JavaScript based on hash tags, can this impact search indexing by Yahoo/Google/Bing? I am contemplating using HTML5 state push fo ...