自製樣式美觀的input組件(以search輸入框為例,含源碼),input含源碼

來源:互聯網
上載者:User

自製樣式美觀的input組件(以search輸入框為例,含源碼),input含源碼

閱讀本文前,讀者需要有一定的html + css的技術功底。

不說廢話,先附上search輸入框的成果:


分析:

1. 組件分解:分解為如下幾個部分:

1)外層:增加一個容器,如div

2)內層:

一個input輸入框

一個按鈕

2. 設定樣式:

1)容器樣式

增加border屬性,樣式代碼:

border: solid 1px #ddd;

增加border圓角邊框,樣式代碼:

border-radius: 5px

2)輸入框樣式

去除border樣式:

border: none

去除輪廓樣式:

outline: 0 none;

3)按鈕樣式

同樣,去除border樣式

border: none

給按鈕增加搜尋背景圖片樣式:

background-image: url("images/ico_sear.gif");
background-repeat: no-repeat; 

設定display樣式為:inline


這樣分解完,相信大家就很容易理解了。

並附上完整實現代碼:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head>  <title> 自製search搜尋方塊組件 </title>  <meta name="Generator" content="EditPlus">  <meta name="Author" content="">  <meta name="Keywords" content="">  <meta name="Description" content="">  <style>.searchBlock{width: 110px;border:solid 1px #ddd;border-radius: 5px;-webkit-border-radius: 5px;-moz-border-radius: 5px;-khtml-border-radius: 5px;}.searchBlock span{float: left;}.searchText{border: none;width: 80px;margin: 2px 5px;outline: 0 none;}.searchBtn{border: none;width: 16px;height: 16px;cursor: pointer;background-image: url("images/ico_sear.gif");background-repeat: no-repeat;display: inline;margin: 2px 0px;}  </style> </head> <body>  <div class="searchBlock"><span><input type="text" id="search" name="search" class="searchText"></span><input type="button" class="searchBtn">  </div> </body></html>
搜尋圖片如下:



通過這樣的一個執行個體,我們也可以做出很多類似的組件了。


著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.