简体   繁体   English

CSS子鼠标悬停,旋转和剪辑:饼图问题

[英]CSS Child Hover, Rotate & Clip: Pie Chart Issues

I have a 3-section pie chart where all 3 sections are virtually identical, yet :hover does not trigger on the first section, and does on the other two. 我有一个3部分饼图,其中所有3个部分实际上都相同,但:hover不会在第一部分触发,而在其他两个部分触发。

There is an identical number of overlapping parent divs for every element, yet the other two work perfectly fine, so that shouldn't be the issue. 每个元素都有相同数量的重叠父div,而其他两个div则工作得很好,所以这不应该成为问题。 This entire situation just screams random obscure feature bug, but I have no idea what to even try to do to "hack-fix" it. 这整个情况只会引起随机的,模糊的功能错误,但我不知道该如何尝试对其进行“修复”。 This behavior has been observed in Chrome, FF and IE 在Chrome,FF和IE中已观察到此行为

(yes, I know the top section is poorly positioned, I removed the extra fixes for simplicity to emphasize the bug) (是的,我知道顶部的位置不正确,为简单起见,我删除了一些额外的补丁来强调该错误)

Full code: codepen.io 完整代码: codepen.io

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

CSS: 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;
}

Use z-index for this 为此使用z-index

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

The other divs were on top of the first one, so you just need a z-index and it will work :) 其他div位于第一个div的顶部,因此您只需要一个z-index即可使用:)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM