CSS設定<input>標籤的背景小圖示

admin發表於2017-11-01

很多網站在使用者名稱和密碼輸入的<input>標籤都設定有背景小圖示,非常的美觀。

下面簡單介紹一下如何實現此種效果。

[HTML] 純文字檢視 複製程式碼執行程式碼
<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<title>螞蟻部落</title>
<style type="text/css"> 
ul{list-style:none;} 
li{height:30px;} 
input{ 
  width:140px; 
  height:20px; 
  line-height:20px; 
  border:1px solid #0CF; 
  padding-left:20px; 
} 
.myname{background:url(mytest/demo/stock_people.png) center left no-repeat;} 
.mypw{background:url(mytest/demo/security.png) center left no-repeat;} 
</style> 
</head> 
<body> 
<ul> 
  <li><input type="text" class="myname" name="username" /></li> 
  <li><input type="text" class="mypw" name="password" /></li> 
</ul> 
</body> 
</html>

以上程式碼實現了我們想要的效果,儘管不夠美觀。方法其實很簡單,就是為<input>標籤設定背景圖片。

特別說明:為<input>標籤設定了左內邊距,為了讓輸入的內容不會覆蓋掉小圖示。

相關文章