我無法讓: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