2015-04-28 63 views
-1

我想改變我的輸入類型文件的風格。以下CSS在Chrome和Opera上運行良好,但不在Mozilla Firefox上運行。爲什麼這個CSS不適用於Firefox?

HTML

<input type="file" class="custom-file-input" /> 

CSS

.custom-file-input::-webkit-file-upload-button { 
    visibility: hidden; 
} 
.custom-file-input::before { 
    content: 'UPLOAD'; 
    display: inline-block; 
    background: -webkit-linear-gradient(top, black, red); 
    border: 1px solid #999; 
    border-radius: 3px; 
    padding: 5px; 
    outline: none; 
    white-space: nowrap; 
    -webkit-user-select: none; 
    cursor: pointer; 
    font-size: 10pt; 
color:#fff; 
} 
.custom-file-input:hover::before { 
    border-color: #fff; 
} 
.custom-file-input:active::before { 
color:#666; 
    background: -webkit-linear-gradient(top, bclack, red); 
} 

http://jsfiddle.net/Rameshpardhi/3agapfw3/

我也改變了我的風格是:

.custom-file-input::-moz-file-upload-button { 
    visibility: hidden; 
} 
.custom-file-input::before { 
    content: 'UPLOAD'; 
    display: inline-block; 
    background: -moz-linear-gradient(top, black, red); 
    border: 1px solid #999; 
    border-radius: 3px; 
    padding: 5px; 
    outline: none; 
    white-space: nowrap; 
    -moz-user-select: none; 
    cursor: pointer; 
    font-size: 10pt; 
color:#fff; 
} 
.custom-file-input:hover::before { 
    border-color: #fff; 
} 
.custom-file-input:active::before { 
color:#666; 
    background: -moz-linear-gradient(top, bclack, red); 
} 

但它仍然沒有工作。我想知道爲什麼這個CSS不適用於Mozzila?

+0

試圖把-moz-在這樣的酒店前臺:-moz-線性漸變(頂部,bclack,紅色); – icode03

+0

解釋發生了什麼問題,應該怎麼做 – Vinc199789

+1

可能重複[如何在Firefox中設置文件輸入字段?](http://stackoverflow.com/questions/352467/how-can-i-style-a- file-input-field-in-firefox) – Flynn1179

回答

0

我不知道這是不是你期望的,但是有一個使用<label>技巧的按鈕的跨瀏覽器版本。 隨意調整CSS(如果你不使用SASS,點擊'view compiled')。

http://codepen.io/mbrillaud/pen/LVEgBy

+0

這很有趣...讓我試試看...謝謝你的回覆 –

+0

有沒有辦法用CSS來做到這一點? –

+0

您需要JS才能獲取輸入的值,因爲輸入是隱藏的。該按鈕仍然沒有它,但你不會看到你選擇了哪個文件。 –

0

注意-webkit-聲明?這僅適用於Chrome和Opera。將它們加倍並用-moz-替換它們,或者將它們全部刪除。

嘗試在您的代碼上運行autoprefixer以獲取正確的代碼。

注意:推薦的結構應該是在輸入字段和樣式周圍有一個標籤。

+0

我試過這個,但它也沒有工作... –

+0

你可以用你試過的更新你的代碼嗎? – Ciprian

相關問題