2016-04-19 196 views
0

我將圖像保存爲透明png,但我無法做的事似乎可以解決它!?!有任何想法嗎???透明PNG不呈現爲透明?

enter image description here

它應該是這樣的:

enter image description here

這裏是GIMP圖像的副本顯示,這是完全透明的:

enter image description here

最後,一些很好的舊代碼:

標記:

<form class="search" action="search.php"><input class="search" type="text" name="search" id="searchbox"/></form> 

搜索框CSS:

.search, .search:active, .search:focus, .search:visited { 
    position: absolute; 
    color: #fff; 
    top: 3px; 
    width: 368px; 
    right: 9%; 
    font-size: 28px; 
    z-index: 3; 
    border-radius: 20px; 
    /* box-shadow: inset -2px 0px 1px rgba(0,0,0,.8); */ 
    text-indent: 10px; 
    text-shadow: 0px -2px 3px rgba(0, 0, 0, .7); 
    background-color: #00D4C7; 
} 

搜索圖標CSS本身:

Pseudo ::before element 
.search:before { 
    content: ""; 
    position: absolute; 
    top: 7px; 
    left: 268px; 
    background-image: url("images/icon-search.png"); 
    background-color: rgb(0, 185, 171); 
    width: 46px; 
    height: 30px; 
    z-index: 4; 
} 

注:如果我從表單中刪除類搜索,它刪除了我的圖像,如果我從輸入元素中刪除了類搜索,它仍然以我的圖像上那種質樸的陰影渲染出來你的想法?

編輯1:如果按照建議的方式設置圖像的顯式尺寸(正如我對其他沒有問題的僞元素所做的那樣),它不能解決我的問題。我已經提交了項目,所以在這一點上,我想知道發生了什麼以及如何解決這個問題。我使出了CSS破解,改變亮度,以更匹配[帶着淡淡的輪廓仍然]

enter image description here

編輯2:顯示我的JS Fiddle

+0

一定要檢查你的CSS以及。您已將「搜索」類應用於表單和輸入元素。 – EdwardM

回答

1

你是給你的圖像background-color: rgb(0, 185, 171);是什麼#00b9ab

和搜索框background-color: #00D4C7;什麼是RGB(0,212,199)

+0

我試圖設置爲透明的元素,根據這個答案沒有解決:http://stackoverflow.com/a/6165704/2226328 – Frankenmint

+0

如果你給他相同的背景顏色? – DanyCode

+0

這就是讓我在這裏開始:http://puu.sh/ookR2/f3a1324590.png – Frankenmint

0

這可能會發生,因爲你的背景圖像尺寸不同於其容器,.search::before,大小。和/或因爲您的背景色是不同的十六進制值。

試試這個: 加background-color: transparent;background-size: 46px 30px;.search::before。這將使得如果你的背景圖像比容器小,剩下的空間將是透明的,並且將背景圖像大小設置爲與你明確設置的容器相同。

+0

我試過了你的建議,但沒有看到改進 – Frankenmint

+0

嗯..你有可能把你的代碼放在jsfiddle中嗎? – smrubin

+0

你的形象沒有通過小提琴,你有一個工作鏈接? – smrubin

0

我的形象本身並不真正透明。有一個小的不透明通道,導致灰色陰霾出現在非白色背景上。我在發佈到imgur時遇到了這個問題......並且當我實際上使用select by color製作了一個圖層副本(在Photoshop中)時確認了這一點。

enter image description here

解決方案:檢查您的圖片...要做到這一點,它本身加載到一個窗口和HTML正文設置爲一個非白色的顏色。祝我認爲要做到這一點提交此之前:

enter image description here