小編給大家分享一下css如何在文本框中設置清除按鈕,希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧!
我們先來看一下設置清除按鈕具體的示例
代碼如下
HTML代碼
<!DOCTYPEhtml>
<html>
<head>
<linkhref="style.css"rel="stylesheet"type="text/css"/>
<scripttype="text/javascript"language="javascript">
<!--
functionClearButton_Click(){
this.searchForm.searchBox.value="";
}
-->
</script>
</head>
<body>
<formaction=""name="searchForm">
<divclass="searchFrame">
<inputtype="text"id="search"name="searchBox"value=""class="inputBox"/>
<divclass="clearButton"onclick="ClearButton_Click()"></div>
</div>
</form>
</body>
</html>
CSS代碼
style.css
.searchFrame{
position:relative;
display:inline-block;
}
.inputBox{
padding-right:20px;
width:120px;
}
.searchFrame.clearButton{
width:13px;
height:13px;
position:absolute;
right:2px;
top:1px;
background:url(img/d.jpg)no-repeatleftcenter;
cursor:pointer;
}
說明
上述代碼中,在文本框周圍準備一個“searchFrame”框架。將清除按鈕放在“searchFrame”框架的右端。通過設置樣式表的正確屬性將其放在右端?!皊earchFrame”框架被指定為“display:inline-block”,它是一個緊緊圍繞文本框的框架。
看完了這篇文章,相信你對“css如何在文本框中設置清除按鈕”有了一定的了解,如果想了解更多相關知識,歡迎關注億速云行業資訊頻道,感謝各位的閱讀!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。