我无法让:hover
与我做的CSS饼片一起工作。我使用透明边框和border-radius
属性来使我的div看起来像饼图的1/4。但是,我试图用于悬停状态的任何样式都不起作用。我猜它是与具有height: 0;
和width: 0;
股利,但我不知道如何解决这个问题?这里是我的代码:使用悬停与特殊的CSS形状
div {
position: absolute;
right: 0;
left: 0;
margin: 0 auto;
width: 0;
\t height: 0;
border-radius: 50%;
}
.circle-1 {
border-left: 50px solid transparent;
\t border-right: 50px solid transparent;
\t border-bottom: 50px solid transparent;
border-top: 50px solid green;
}
.circle-1:hover {
border-top: 50px solid pink;
cursor: pointer;
}
.circle-2 {
border-left: 50px solid transparent;
\t border-right: 50px solid red;
\t border-bottom: 50px solid transparent;
border-top: 50px solid transparent;
}
.circle-3 {
border-left: 50px solid transparent;
\t border-right: 50px solid transparent;
\t border-bottom: 50px solid blue;
border-top: 50px solid transparent;
}
.circle-4 {
border-left: 50px solid orange;
\t border-right: 50px solid transparent;
\t border-bottom: 50px solid transparent;
border-top: 50px solid transparent;
}
<div class="circle-1"></div>
<div class="circle-2"></div>
<div class="circle-3"></div>
<div class="circle-4"></div>
它会是一个更好的主意,在这个答案在这里使用SVG像 - http://stackoverflow.com/questions/27943053/how-to-create-a-circle -with-links-on-border-side/34902989#34902989(我知道':hover'不存在于该演示中,但应该很容易添加它。)问题中的':hover'选择器不起作用因为你已经将4个元素放在彼此的顶部,所以即使边框颜色是透明的,你有权访问的唯一元素是第四个元素。如果你把'.circle-4:hover',它会起作用,但是它仍然不能达到你所需要的全部。 – Harry