您好,登錄后才能下訂單哦!
這篇文章主要講解了“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)容到剪貼板
<div class="fileUpload btn btn-primary">
<span>Upload</span>
<input type="file" class="upload" />
</div>
第2步:CSS: 有點(diǎn)棘手了
JavaScript Code復(fù)制內(nèi)容到剪貼板
.fileUpload {
position: relative;
overflow: hidden;
margin: 10px;
}
.fileUpload input.upload { position: absolute;
top: 0;
right: 0;
margin: 0;
padding: 0;
font-size: 20px;
cursor: pointer;
opacity: 0;
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);
}
為簡(jiǎn)單起見,我使用應(yīng)用了BootstrapCSS樣式的按鈕 (div.file-upload)。
演示:
上傳按鈕,顯示選中的文件
不幸的是純CSS的做不到這一點(diǎn)。但是,如果你真的想顯示所選文件,下面的JavaScript代碼片段可以幫助你。
JavaScript:
JavaScript Code復(fù)制內(nèi)容到剪貼板
document.getElementById("uploadBtn").onchange = function () {
document.getElementById("uploadFile").value = this.value;
};
DOM:
JavaScript Code復(fù)制內(nèi)容到剪貼板
<input id="uploadFile" placeholder="Choose File" disabled="disabled" />
<div class="fileUpload btn btn-primary">
<<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>
<input id="uploadBtn" type="file" class="upload" />
</div>
演示:
感謝各位的閱讀,以上就是“css怎么更改上傳按鈕的樣式”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對(duì)css怎么更改上傳按鈕的樣式這一問題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是億速云,小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!
免責(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)容。