自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

超酷HTML 5和CSS3實現(xiàn)登錄及注冊功能表單

開發(fā) 前端
我們將會談到登錄和注冊功能使用純CSS3和HTML 5來實現(xiàn)。這里我們使用CSS3的偽類:target。我們使用CSS3和圖標字體。

超酷HTML5和CSS3實現(xiàn)的登錄及其注冊功能表單

在線演示 本地下載

過去我們開發(fā)登錄和注冊功能大都使用javascript來實現(xiàn),今天我們介紹的這個登錄及其注冊表單不走常人路,使用純CSS3和HTML5來實現(xiàn)同樣的功能。

這里我們使用CSS3的偽類:target。我們使用CSS3和圖標字體。主要的想法是展示登錄表單并且提供一個鏈接可以轉(zhuǎn)向注冊表單。

請大家注意這里只是一個簡單的演示,不是所有的瀏覽器都支持:target,如果你需要在產(chǎn)品環(huán)境中使用,你需要使用對應(yīng)的代碼來處理對于老瀏覽器支持的fallback。

HTML

在html代碼中,我們構(gòu)建倆個表單并且把第二個表單隱藏。如下:

  1. <div id="container_demo" > 
  2.     <!-- hidden anchor to stop jump http://www.css3create.com/Astuce-Empecher-le-scroll-avec-l-utilisation-de-target#wrap4  --> 
  3.     <a class="hiddenanchor" id="toregister"></a> 
  4.     <a class="hiddenanchor" id="tologin"></a> 
  5.     <div id="wrapper"> 
  6.         <div id="login" class="animate form"> 
  7.             <form  action="mysuperscript.php" autocomplete="on"> 
  8.                 <h1>Log in</h1> 
  9.                 <p> 
  10.                     <label for="username" class="uname" data-icon="u" > Your email or username </label> 
  11.                     <input id="username" name="username" required="required" type="text" placeholder="myusername or mymail@mail.com"/> 
  12.                 </p> 
  13.                 <p> 
  14.                     <label for="password" class="youpasswd" data-icon="p"> Your password </label> 
  15.                     <input id="password" name="password" required="required" type="password" placeholder="eg. X8df!90EO" /> 
  16.                 </p> 
  17.                 <p class="keeplogin"> 
  18.                     <input type="checkbox" name="loginkeeping" id="loginkeeping" value="loginkeeping" /> 
  19.                     <label for="loginkeeping">Keep me logged in</label> 
  20.                 </p> 
  21.                 <p class="login button"> 
  22.                     <input type="submit" value="Login" /> 
  23.                 </p> 
  24.                 <p class="change_link"> 
  25.                     Not a member yet ?  
  26.                     <a href="#toregister" class="to_register">Join us</a> 
  27.                 </p> 
  28.             </form> 
  29.         </div> 
  30.    
  31.         <div id="register" class="animate form"> 
  32.             <form  action="mysuperscript.php" autocomplete="on"> 
  33.                 <h1> Sign up </h1> 
  34.                 <p> 
  35.                     <label for="usernamesignup" class="uname" data-icon="u">Your username</label> 
  36.                     <input id="usernamesignup" name="usernamesignup" required="required" type="text" placeholder="mysuperusername690" /> 
  37.                 </p> 
  38.                 <p> 
  39.                     <label for="emailsignup" class="youmail" data-icon="e" > Your email</label> 
  40.                     <input id="emailsignup" name="emailsignup" required="required" type="email" placeholder="mysupermail@mail.com"/> 
  41.                 </p> 
  42.                 <p> 
  43.                     <label for="passwordsignup" class="youpasswd" data-icon="p">Your password </label> 
  44.                     <input id="passwordsignup" name="passwordsignup" required="required" type="password" placeholder="eg. X8df!90EO"/> 
  45.                 </p> 
  46.                 <p> 
  47.                     <label for="passwordsignup_confirm" class="youpasswd" data-icon="p">Please confirm your password </label> 
  48.   <input id="passwordsignup_confirm" name="passwordsignup_confirm" required="required" type="password" placeholder="eg. X8df!90EO"/> 
  49.                 </p> 
  50.                 <p class="signin button"> 
  51.                     <input type="submit" value="Sign up"/> 
  52.                 </p> 
  53.                 <p class="change_link"> 
  54.                     Already a member ?  
  55.                     <a href="#tologin" class="to_register"> Go and log in </a> 
  56.                 </p> 
  57.             </form> 
  58.         </div> 
  59.     </div> 
  60. </div>  

我 們在這里添加了HTML5相關(guān)元素,并且使用了一些新的輸入控件。input=password自動隱藏用戶輸入。input=email使得瀏覽器檢查 是否用戶輸入是正確的email。同時我們添加了require=required屬性。支持這個屬性的瀏覽器將不允許用戶遞交表單除非所有的輸入?yún)^(qū)域都 是正確,大家可能注意到這里不需要使用javascript。autocomplete=on屬性將會基于用戶輸入預(yù)先的填入內(nèi)容。我們同時也可以使用一 些不錯的placeholder來提示用戶應(yīng)該輸入的內(nèi)容。

接下來可能是倆個比較有趣的部分。你或許注意到了頂端的倆個<a href>鏈接。這是一個能夠幫助我們的表單更加方便的使用anchor處理的小技巧,這樣當我們點擊切換鏈接并且觸發(fā):target的時候?qū)⒉粫缭胶荛L的頁面。

第二個小技巧是使用icon字體。我們將會使用一個data-attribute來展示圖標。通過使用對應(yīng)的字符來設(shè)定data-icon="icon_charactoer",我們只需要一個CSS屬性選擇器來樣式化所有的圖標。如果你對這個有興趣,可以閱讀:24 Ways: Displaying Icons with Fonts and Data- Attributes

CSS

為了使得代碼更加清晰,在教程里我們忽略了瀏覽器提供商指定的前綴, 當然你可以在對應(yīng)代碼中找到相關(guān)的設(shè)定。當然我們使用了很多不錯的CSS3技巧可能不在所有的瀏覽器中生效。

倆個表單的樣式

首先我們配置容器的樣式:

  1. #subscribe,  
  2. #login{  
  3.     positionabsolute;  
  4.     top: 0px;  
  5.     width88%;  
  6.     padding18px 6% 60px 6%;  
  7.     margin0 0 35px 0;  
  8.     backgroundrgb(247247247);  
  9.     border1px solid rgba(147184189,0.8);  
  10.     box-shadow:  
  11.         0pt 2px 5px rgba(105108109,  0.7),  
  12.         0px 0px 8px 5px rgba(2082232260.4inset;  
  13.     border-radius: 5px;  
  14. }  
  15. #login{  
  16.     z-index22;  

這里我們添加了一個漂亮的盒式陰影(box shadow)來創(chuàng)建2個陰影:一個inset用來創(chuàng)建內(nèi)部藍色,還有一個外部陰影。這里我們稍微解釋一下z-index。

在下面代碼中,我們定義了標題的樣式,使用了background-clip。

  1. /**** general text styling ****/ 
  2. #wrapper h1{  
  3.     font-size48px;  
  4.     colorrgb(6106117);  
  5.     padding2px 0 10px 0;  
  6.     font-family'FranchiseRegular','Arial Narrow',Arial,sans-serif;  
  7.     font-weightbold;  
  8.     text-aligncenter;  
  9.     padding-bottom30px;  
  10. }  
  11.    
  12. /** For the moment only webkit supports the background-clip:text; */ 
  13. #wrapper h1{  
  14.     background:  
  15.     -webkit-repeating-linear-gradient(-45deg,  
  16.         rgb(188393) ,  
  17.         rgb(18839320px,  
  18.         rgb(6411111820px,  
  19.         rgb(6411111840px,  
  20.         rgb(18839340px);  
  21.     -webkit-text-fill-colortransparent;  
  22.     -webkit-background-clip: text;  
  23. }  
  24.    
  25. #wrapper h1:after{  
  26.     content:' ';  
  27.     display:block;  
  28.     width:100%;  
  29.     height:2px;  
  30.     margin-top:10px;  
  31.     background:  
  32.         linear-gradient(left,  
  33.             rgba(147,184,189,00%,  
  34.             rgba(147,184,189,0.820%,  
  35.             rgba(147,184,189,153%,  
  36.             rgba(147,184,189,0.879%,  
  37.             rgba(147,184,189,0100%);  

大家注意目前只有webkit的瀏覽器支持background-clip,所以我們將只為webkit創(chuàng)建條紋式的背景,我們將這個特效添加到H1標題。 因為目前只能在webkit瀏覽器上生效,我們將使用webkit前綴。只使用-webkit-prefix是一個糟糕的習(xí)慣,這里只是為了演示,你不應(yīng) 該在一個正式的網(wǎng)站中使用!-webkit-text-fill-color:trasparent幫助你生成一個透明的背景。當然其它瀏覽器都會忽略。

我們使用:after偽類來在標題下創(chuàng)建了一個淡出的直線效果。我們對直線兩端使用2px的高度漸變并且淡出背景到0。

接下來我們使的輸入更好漂亮。

  1. /**** advanced input styling ****/ 
  2. /* placeholder */ 
  3. ::-webkit-input-placeholder  {  
  4.     colorrgb(190188188);  
  5.     font-styleitalic;  
  6. }  
  7. input:-moz-placeholder,  
  8. textarea:-moz-placeholder{  
  9.     colorrgb(190188188);  
  10.     font-styleitalic;  
  11. }  
  12. input {  
  13.   outlinenone;  

首先我們定義了input樣式并且刪除了outline。注意outline幫助用戶知道目前聚焦到那個輸入項,如果你刪除你應(yīng)該提供:active和:focus。

  1. /* all the input except submit and checkbox */ 
  2. #wrapper input:not([type="checkbox"]){  
  3.     width92%;  
  4.     margin-top4px;  
  5.     padding10px 5px 10px 32px;  
  6.     border1px solid rgb(178178178);  
  7.     box-sizing : content-box;  
  8.     border-radius: 3px;  
  9.     box-shadow: 0px 1px 4px 0px rgba(1681681680.6inset;  
  10.     transition: all 0.2s linear;  
  11. }  
  12. #wrapper input:not([type="checkbox"]):active,  
  13. #wrapper input:not([type="checkbox"]):focus{  
  14.     border1px solid rgba(9190900.7);  
  15.     background: rgba(2382362400.2);  
  16.     box-shadow: 0px 1px 4px 0px rgba(1681681680.9inset;  

這里我們使用:not pseudo class,來定義所有input樣式,除了checkbox。我提供了一個:focus和:active狀態(tài),因為我們要刪除outline。

接 下來我們介紹icon字體部分。因為對于input來說我們沒有辦法添加:before和:class偽類,所以我們需要作弊一下:我們添加icon到 label,然后添加到input中。這里我們使用fontomas library的圖標。 記得data-icon屬性吧?在這里我們使用data-icon='u'代表用戶,'e'代表電子郵件,'p'代表密碼。一旦選擇這些字母,我們下載字 體,并且使用fontsquirrel font generator來將他們生成@font-face兼容格式。

  1. @font-face {  
  2.     font-family'FontomasCustomRegular';  
  3.     srcurl('fonts/fontomas-webfont.eot');  
  4.     srcurl('fonts/fontomas-webfont.eot?#iefix'format('embedded-opentype'),  
  5.          url('fonts/fontomas-webfont.woff'format('woff'),  
  6.          url('fonts/fontomas-webfont.ttf'format('truetype'),  
  7.          url('fonts/fontomas-webfont.svg#FontomasCustomRegular'format('svg');  
  8.     font-weightnormal;  
  9.     font-stylenormal;  
  10. }  
  11.    
  12. /** the magic icon trick ! **/ 
  13. [data-icon]:after {  
  14.     contentattr(data-icon);  
  15.     font-family'FontomasCustomRegular';  
  16.     colorrgb(106159171);  
  17.     positionabsolute;  
  18.     left: 10px;  
  19.     top: 35px;  
  20.     width30px;  

沒錯,你不需要為每一個圖標設(shè)置class。我們使用content:attr(data-icon)來取得字母,因此我們只需要申明字體,選擇顏色并且定義位置。

接下來我們定義遞交按鈕:

  1. /*styling both submit buttons */ 
  2. #wrapper p.button input{  
  3.     width30%;  
  4.     cursorpointer;  
  5.     backgroundrgb(61157179);  
  6.     padding8px 5px;  
  7.     font-family'BebasNeueRegular','Arial Narrow',Arial,sans-serif;  
  8.     color#fff;  
  9.     font-size24px;  
  10.     border1px solid rgb(28108122);  
  11.     margin-bottom10px;  
  12.     text-shadow0 1px 1px rgba(0000.5);  
  13.     border-radius: 3px;  
  14.     box-shadow:  
  15.         0px 1px 6px 4px rgba(0000.07inset,  
  16.         0px 0px 0px 3px rgb(254254254),  
  17.         0px 5px 3px 3px rgb(210210210);  
  18.     transition: all 0.2s linear;  
  19. }  
  20. #wrapper p.button input:hover{  
  21.     backgroundrgb(74179198);  
  22. }  
  23. #wrapper p.button input:active,  
  24. #wrapper p.button input:focus{  
  25.     backgroundrgb(40137154);  
  26.     positionrelative;  
  27.     top: 1px;  
  28.     border1px solid rgb(127687);  
  29.     box-shadow: 0px 1px 6px 4px rgba(0000.2inset;  
  30. }  
  31. p.login.button,  
  32. p.signin.button{  
  33.     text-alignright;  
  34.     margin5px 0;  

這里我們主要使用box-shadow來創(chuàng)建多余的border。你可以使用一個邊框,但是也可以創(chuàng)建更多。我們使用length數(shù)值來創(chuàng)建一個假的白色邊框,3px寬,沒有模糊。

開發(fā)完畢,希望大家喜歡這個教程,如果你想看到所有效果,使用Chrome來運行在線演示吧,謝謝大家支持!

原文鏈接:http://www.cnblogs.com/gbin1/archive/2012/04/09/2439806.html

【編輯推薦】

  1. 8個非常有用的HTML 5工具你值得擁有
  2. 6個優(yōu)秀的HTML 5/CSS3演示PPT框架推薦
  3. 解決跨平臺問題的終極密鑰就是HTML 5?
  4. HTML 5開發(fā):地理位置定位指南
  5. 一句代碼實現(xiàn)HTML 5淘寶語音搜索
責任編輯:彭凡 來源: 博客園
相關(guān)推薦

2011-07-15 09:10:44

HTML 5CSS3

2012-02-29 09:27:36

ibmdw

2013-08-21 13:19:33

HTML5CSS3表單設(shè)計

2011-03-22 08:54:02

HTML 5CSS3JavaScript

2012-05-11 09:37:34

HTML5

2010-03-22 08:56:12

2012-05-24 11:03:55

HTML5

2014-07-14 12:37:36

jQueryCSS3

2011-11-25 13:18:40

HTML 5

2011-08-30 16:39:34

HTML 5

2012-05-30 09:22:56

Hybrid App助HTML5JavaScript

2011-11-17 09:24:27

HTML 5

2013-07-09 09:24:29

響應(yīng)式HTML5CSS3

2011-11-18 13:25:48

HTML 5

2012-05-25 10:31:44

HTML5

2011-06-17 08:54:38

HTML 5CSS3

2011-09-21 11:02:17

HTML 5

2011-01-25 09:16:33

HTML 5CSS3Web

2011-05-11 16:13:43

CSS3

2012-06-07 09:23:45

ibmdw
點贊
收藏

51CTO技術(shù)棧公眾號