這個search是個自定義的類名,也就是說如果有多個元素設定了這個類名,那么只要在css中給這個類設定樣式,那么這些元素都會是同樣的樣式。

讓客戶滿意是我們工作的目標,不斷超越客戶的期望值來自于我們對這個行業(yè)的熱愛。我們立志把好的技術通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領域值得信任、有價值的長期合作伙伴,公司提供的服務項目有:域名注冊、網(wǎng)站空間、營銷軟件、網(wǎng)站建設、盧龍網(wǎng)站維護、網(wǎng)站推廣。
補充說一下:類名是可以任意設置的,只要符合html的命名規(guī)則即可。也就是說,“search”在這里只是個名字,本身不具有意義,就好像問“姚明是什么意思”一樣。
另外,name在這里也是個類名,當一個class同時設置多個類名時,它會自動把這些類的css樣式進行合并(如果樣式之間存在沖突,則后面的會覆蓋前面的)。
再再補充一下:一個元素具有多個類,你可以在生活中隨處找到例子,比如說一個人按性別分是男人,按年齡分是青年,按文化程度分是大學生,那么他就同時具有男人、青年、大學生的屬性,即 class="男人 青年 大學生"
Wordpress自帶的主題上放置了一個可以伸縮的搜索框。使用簡單的幾行CSS就能完成它,當然,前提條件是,你要使用支持CSS3的現(xiàn)代瀏覽器。
HTML 元素像img 和input 都沒有內(nèi)容,所以,像before這樣的偽元素不會為我們的搜索框呈現(xiàn)任何箭頭。我的解決方案是使用button type=“submit” 元素代替普通的input type=“submit”。這樣,我們就可以用ENTER鍵來提交表單。
css3選擇器如下:
一、通配符選擇器(*)
通配符選擇器是用來選擇所有元素,,也可以選擇某個元素下的所有元素。
二、元素選擇器(E)
元素選擇器,是css選擇器中最常見而且最基本的選擇器。
三、類選擇器(.className)
類選擇器是以一獨立于文檔元素的方式來指定樣式,使用類選擇器之前需要在html元素上定義類名
四、id選擇器(#ID)
ID選擇器和上面說的類選擇器是很相似的,在使用ID選擇器之前也需要先在html文檔中加注ID名稱,這樣在樣式選擇器中才能找到相對應的元素,不同的是ID選擇器是一個頁面中唯一的值,我們在類使用時是在相對應的類名前加上一個“.”號(.className)而id選擇器是在名稱前使用"#"如(#id),
五、后代選擇器(E F)
后代選擇器也被稱作包含選擇器,所起作用就是可以選擇某元素的后代元素,比如說:E?
F,前面E為祖先元素,F(xiàn)為后代元素,所表達的意思就是選擇了E元素的所有后代F元素,請注意他們之間需要一個空格隔開。
六、子元素選擇器(Egt;F)
子元素選擇器只能選擇某元素的子元素,其中E為父元素,而F為子元素,其中Egt;F所表示的是選擇了E元素下的所有子元素F。這和后代選擇器(E?
F)不一樣,在后代選擇器中F是E的后代元素,而子元素選擇器E gt; F,其中F僅僅是E的子元素而以。
七、相鄰兄弟元素選擇器(E + F)
相鄰兄弟選擇器可以選擇緊接在另一元素后的元素,而且他們具有一個相同的父元素,換句話說,EF兩元素具有一個相同的父元素,而且F元素在E元素后面,而且相鄰,這樣我們就可以使用相鄰兄弟元素選擇器來選擇F元素。
1、新建html文檔。
2、書寫hmtl代碼。
div class="container"
div id="search"
label for="search"點擊查看效果(a href="#" target="_blank"11111111111/a):/label
input type="text" name="q"
input class="button" type="submit" value="Search"
/div
/div
3、書寫css代碼。
style
body { background-color: #f1f1f1; margin: 0; }
body, ?input, ?button { font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; }
.container { margin: 30px auto 40px auto; width: 800px; text-align: center; }
a { color: #4183c4; text-decoration: none; font-weight: bold; }
a:hover { text-decoration: underline; }
h3 { color: #666; }
ul { list-style: none; padding: 25px 0; }
li { display: inline; margin: 10px 50px 10px 0px; }
input[type=text], ?input[type=password] { font-size: 13px; min-height: 32px; margin: 0;
padding: 7px 8px; outline: none; color: #333; background-color: #fff; background-repeat:
no-repeat; background-position: right center; border: 1px solid #ccc; border-radius: 3px;
box-shadow: inset 0 1px 2px rgba(0,0,0,0.075); -moz-box-sizing: border-box; box-sizing:
border-box; transition: all 0.15s ease-in; -webkit-transition: all 0.15s ease-in 0; vertical-align: middle; }
button { position: relative; display: inline-block; margin: 0; padding: 8px 15px; font-size:
13px; font-weight: bold; color: #333; text-shadow: 0 1px 0 rgba(255,255,255,0.9); white
space: nowrap; background-color: #eaeaea; background-image: -moz-linear
gradient(#fafafa, #eaeaea); background-image: -webkit-linear-gradient(#fafafa, #eaeaea);
background-image: linear-gradient(#fafafa, #eaeaea); background-repeat: repeat-x;
border-radius: 3px; border: 1px solid #ddd; border-bottom-color: #c5c5c5; box-shadow:
01px 3px rgba(0,0,0,.05); vertical-align: middle; cursor: pointer; -moz-box-sizing: border-box;
box-sizing: border-box; -webkit-touch-callout: none; -webkit-user-select: none; -khtml
user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none;
webkit-appearance: none; }
.button:hover, ?.button:active { background-position: 0 -15px; border-color: #ccc #ccc
#b5b5b5; }
.button:active { background-color: #dadada; border-color: #b5b5b5; background-image:
none; box-shadow: inset 0 3px 5px rgba(0,0,0,.15); }
.button:focus, ?input[type=text]:focus, ?input[type=password]:focus { outline: none; border
color: #51a7e8; box-shadow: inset 0 1px 2px rgba(0,0,0,.075), 0 0 5px rgba(81,167,232,.5); }
label[for=search] { display: block; text-align: left; }
#search label { font-weight: 200; padding: 5px 0; }
#search input[type=text] { font-size: 18px; width: 705px; }
#search .button { padding: 10px; width: 90px; }
/style
4、代碼整體結(jié)構。
5、查看效果。
無論是網(wǎng)站還是web應用,都會為了增強用戶體驗而添加它,那么你是不是也想過設計一個別致的搜索框?在今天的文章中,大家將會學到如何使用偽元素來創(chuàng)建一個超酷的CSS3搜索框。當然在開始介紹前你也可以下載源代碼或者查看在線演示。HTML舉例:正如接下來你所看到的,標記很少,并且很容易理解:form class=“cf form-wrapper”input type=“text” placeholder=“Search here.。.” requiredbutton type=“submit”Search/button/form你可能注意到了HTML5的特殊屬性,像placeholder和required,簡介如下:.placeholder-基本上,這個屬性的作用在于當文本框獲得焦點之前,先在文本框里顯示一個域的信息,直到獲得焦點后,域的信息被隱藏。.required-這個屬性說明了當前元素是表單提交中的一個必需屬性。HTML5也給我們帶來了一個新的type屬性:type="search"。小貼士:HTML 元素像img 和input 都沒有內(nèi)容,所以,像before這樣的偽元素不會為我們的搜索框呈現(xiàn)任何箭頭。我的解決方案是使用button type=“submit” 元素代替普通的input type=“submit”。這樣,我們就可以用ENTER鍵來提交表單。CSS舉例接下來,你將會看到demo里必要的樣式:清除浮動.cf:before, .cf:after{content:“”;display:table;}.cf:after{clear:both;}.cf{zoom:1;}表單元素有前綴的屬性像-moz、-box、-shadow 不包括在內(nèi),我只想讓下面的代碼保持干凈。/* Form wrapper styling */.form-wrapper {width: 450px;padding: 15px;margin: 150px auto 50px auto;background: #444;background: rgba(0,0,0,.2);border-radius: 10px;box-shadow: 0 1px 1px rgba(0,0,0,.4) inset, 0 1px 0 rgba(255,255,255,.2);}/* Form text input */.form-wrapper input {width: 330px;height: 20px;padding: 10px 5px;float: left;font: bold 15px ‘lucida sans’,‘trebuchet MS’,‘Tahoma’;border: 0;background: #eee;border-radius: 3px 0 0 3px;}.form-wrapper input:focus {outline: 0;background: #fff;box-shadow: 0 0 2px rgba(0,0,0,.8) inset;}.form-wrapper input::-webkit-input-placeholder {color: #999;font-weight: normal;font-style: italic;}.form-wrapper input:-moz-placeholder {color: #999;font-weight: normal;font-style: italic;}.form-wrapper input:-ms-input-placeholder {color: #999;font-weight: normal;font-style: italic;}/* Form submit button */.form-wrapper button {overflow: visible;position: relative;float: right;border: 0;padding: 0;cursor: pointer;height: 40px;width: 110px;font: bold 15px/40px ‘lucida sans’,‘trebuchet MS’,‘Tahoma’;color: #fff;text-transform: uppercase;background: #d83c3c;border-radius: 0 3px 3px 0;text-shadow: 0 -1px 0 rgba(0, 0 ,0, .3);}.form-wrapper button:hover{background: #e54040;}.form-wrapper button:active,.form-wrapper button:focus{background: #c42f2f;outline: 0;}.form-wrapper button:before { /* left arrow */content: ‘’;position: absolute;border-width: 8px 8px 8px 0;border-style: solid solid solid none;border-color: transparent #d83c3c transparent;top: 12px;left: -6px;}.form-wrapper button:hover:before{border-right-color: #e54040;}.form-wrapper button:focus:before,.form-wrapper button:active:before{border-right-color: #c42f2f;}.form-wrapper button::-moz-focus-inner { /* remove extra button spacing for Mozilla Firefox */border: 0;padding: 0;}希望大家能喜歡這個教程,并且期待你們的反饋。
當前標題:css3搜索框樣式,css設置搜索框
當前地址:http://chinadenli.net/article47/dsggpej.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供小程序開發(fā)、響應式網(wǎng)站、外貿(mào)建站、網(wǎng)站營銷、域名注冊、靜態(tài)網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)