溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

css怎么更改上傳按鈕的樣式

發(fā)布時(shí)間:2021-08-26 15:30:52 來源:億速云 閱讀:122 作者:chen 欄目:web開發(fā)

這篇文章主要講解了“css怎么更改上傳按鈕的樣式”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“css怎么更改上傳按鈕的樣式”吧!

我們的目標(biāo)是創(chuàng)造一個(gè)簡(jiǎn)潔,用純CSS實(shí)現(xiàn)的,在所有瀏覽器里的樣子和布局是一樣的上傳文件按鈕。我們可以這樣:

  步驟1.創(chuàng)建一個(gè)簡(jiǎn)單的HTML標(biāo)記 
 

XML/HTML Code復(fù)制內(nèi)容到剪貼板

  1. <div class="fileUpload btn btn-primary">  

  2.     <span>Upload</span>  

  3.     <input type="file" class="upload" />  

  4. </div>  

  第2步:CSS: 有點(diǎn)棘手了
 

JavaScript Code復(fù)制內(nèi)容到剪貼板

  1. .fileUpload {   

  2.     position: relative;   

  3.     overflow: hidden;   

  4.     margin: 10px;   

  5. }   

  6.     

  7. .fileUpload input.upload {  position: absolute;   

  8.     top: 0;   

  9.     right: 0;   

  10.     margin: 0;   

  11.     padding: 0;   

  12.     font-size: 20px;   

  13.     cursor: pointer;   

  14.     opacity: 0;   

  15.     filter: <span style="width: auto; height: auto; float: none;" id="3_nwp"><a style="text-decoration: none;" mpid="3" target="_blank" href="http://cpro.baidu.com/cpro/ui/uijs.php?adclass=0&app_id=0&c=news&cf=1001&ch=0&di=128&fv=0&is_app=0&jk=ef23810e363b7f29&k=alpha&k0=alpha&kdi0=0&luki=3&n=10&p=baidu&q=06011078_cpr&rb=0&rs=1&seller_id=1&sid=297f3b36e8123ef&ssp2=1&stid=0&t=tpclicked3_hc&tu=u1922429&u=http%3A%2F%2Fwww%2Eadmin10000%2Ecom%2Fdocument%2F5405%2Ehtml&urlid=0" id="3_nwl"><span style="color:#0000ff;font-size:14px;width:auto;height:auto;float:none;">alpha</span></a></span>(opacity=0);   

  16. }   

  為簡(jiǎn)單起見,我使用應(yīng)用了BootstrapCSS樣式的按鈕  (div.file-upload)。

  演示:

css怎么更改上傳按鈕的樣式

上傳按鈕,顯示選中的文件

  不幸的是純CSS的做不到這一點(diǎn)。但是,如果你真的想顯示所選文件,下面的JavaScript代碼片段可以幫助你。

  JavaScript: 
 

JavaScript Code復(fù)制內(nèi)容到剪貼板

  1. document.getElementById("uploadBtn").onchange = function () {   

  2.     document.getElementById("uploadFile").value = this.value;   

  3. };   

  DOM:
 

JavaScript Code復(fù)制內(nèi)容到剪貼板

  1. <input id="uploadFile" placeholder="Choose File" disabled="disabled" />   

  2. <div class="fileUpload btn btn-primary">   

  3.     <<span style="width: auto; height: auto; float: none;" id="1_nwp"><a style="text-decoration: none;" mpid="1" target="_blank" href="http://cpro.baidu.com/cpro/ui/uijs.php?adclass=0&app_id=0&c=news&cf=1001&ch=0&di=128&fv=0&is_app=0&jk=ef23810e363b7f29&k=span&k0=span&kdi0=0&luki=7&n=10&p=baidu&q=06011078_cpr&rb=0&rs=1&seller_id=1&sid=297f3b36e8123ef&ssp2=1&stid=0&t=tpclicked3_hc&tu=u1922429&u=http%3A%2F%2Fwww%2Eadmin10000%2Ecom%2Fdocument%2F5405%2Ehtml&urlid=0" id="1_nwl"><span style="color:#0000ff;font-size:14px;width:auto;height:auto;float:none;">span</span></a></span>>Upload</span>   

  4.     <input id="uploadBtn" type="file" class="upload" />   

  5. </div>   

  演示:

css怎么更改上傳按鈕的樣式

感謝各位的閱讀,以上就是“css怎么更改上傳按鈕的樣式”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對(duì)css怎么更改上傳按鈕的樣式這一問題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是億速云,小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

css
AI