2010-08-19 105 views

回答

7

CSS3中有一個名爲「rgba」的新值,它允許您使用透明顏色作爲背景顏色。例如:

li:hover { 
    background-color: rgba(255, 255, 255, 0.5); 
} 

我相當肯定,應該工作,雖然我只寫了當場所以它可能不是代碼。然而,這會給你的菜單帶來白色的色彩。如果您想了解更多關於RGBA的信息,請點擊這裏:http://css-tricks.com/rgba-browser-support/

+0

這是最簡單的解決方案,但缺少IE和FF2支持是*大*缺點 – 2010-08-19 22:48:18

+0

對於OP:請注意,CSS3與所有瀏覽器尚不兼容。如果這不會打擾你,這是一個很好的答案。 – 2010-08-19 22:48:53

+0

@皮卡擊敗我。 Haha – 2010-08-19 22:49:11

0

您不能。透明度級別傳遞給所有子元素。

您的選擇:

  • 放在li的頂部的另一個因素,可能使用position: absolute,具有正常的不透明度設置

  • 使用PNG文件與阿爾法透明度創建不透明效果(需要解決方法才能在IE6中工作)

  • 使用新的rgba顏色屬性,如@hatkirby所示,如果您可以接受inc omplete瀏覽器支持

0

你需要使用一個透明的PNG圖像,或rgba colour value,爲<li>的背景,如:

li:hover { 
    background-color: rgba(0, 0, 0, 0.5); 
} 

或者:

li:hover { 
    background: url(a-nice-semi-transparent-png-image.png); 

    /* Supplying just the image file here will make the browser repeat the image 
    file vertically and horizontally, thus taking up all the space, just like a 
    colour would */ 
} 
相關問題