新聞中心
這篇文章將為大家詳細(xì)講解有關(guān)如何使用CSS3制作一個(gè)material-design 風(fēng)格登錄界面,小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。
創(chuàng)新互聯(lián)長期為1000多家客戶提供的網(wǎng)站建設(shè)服務(wù),團(tuán)隊(duì)從業(yè)經(jīng)驗(yàn)10年,關(guān)注不同地域、不同群體,并針對(duì)不同對(duì)象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺(tái),與合作伙伴共同營造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為開江企業(yè)提供專業(yè)的網(wǎng)站制作、網(wǎng)站建設(shè),開江網(wǎng)站改版等技術(shù)服務(wù)。擁有十多年豐富建站經(jīng)驗(yàn)和眾多成功案例,為您定制開發(fā)。心血來潮,想學(xué)學(xué) material design 的設(shè)計(jì)風(fēng)格,就嘗試完成了一個(gè)登錄頁面制作.
這是整體效果.
感覺還不錯(cuò)吧,結(jié)尾會(huì)附上代碼
在編寫的過程中,沒有使用任何圖片或者字體圖標(biāo),全部使用css3完成,還是遇到一些難點(diǎn)和bug,所以想筆記下來,以后方便查閱.
響應(yīng)式設(shè)計(jì)
在這個(gè)頁面中,使用下面3點(diǎn)來完成響應(yīng)式設(shè)計(jì)
1、較大寬度 .設(shè)定了一個(gè) max-width 的較大寬度,以便在大屏幕時(shí)兼容.
2、margin : 20px auto; 使其保持時(shí)刻居中
3、組件使用像素
關(guān)于響應(yīng)式的設(shè)計(jì)要點(diǎn)還有很多。
整體頁面布局
Document
CSS 開始
給 body 添加樣式
html { font-family: "Microsoft YaHei", 宋体, "Segoe UI", "Lucida Grande", Helvetica, Arial, sans-serif, FreeSans, Arimo; background-color: #FF4081; color: #777; }
版心
.container{ position: relative; max-width: 360px; margin: 0 auto; margin-top: 30px; padding: 45px 20px; border-radius: 4px; box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.3); background-color: #fff; box-sizing: border-box; }
注意,這里調(diào)整內(nèi)部邊距使用了padding 而不是對(duì)子元素使用margin,因?yàn)槿绻褂胢argin,為了BFC 的效果,就需要加上 overflow: hidden. 這樣就會(huì)對(duì)尾部按鈕溢出產(chǎn)生影響.
頭部logo
.container>.logo { height: 150px; width: 150px; position: relative; background-color: #EFEFEF; border-radius: 75px; margin: 0 auto; }
設(shè)置 border-radius 為 width和height的一般,就會(huì)使其成為一個(gè)圓
下面需要一個(gè)顏色更深的半圓
如何繪制一個(gè)半圓?
.container>.logo::after { content: ' '; height: 150px; width: 75px; position: absolute; background-color: #E1E1E1; border-radius: 0 75px 75px 0; left: 75px; top: 0; }
設(shè)置寬度為高度的一般,然后設(shè)置左上角和左下角圓角為0,右邊為75px
制作鎖,分為兩部分,lock-top 和 lock -bottom
.container>.logo>.logo-block-top { box-sizing: border-box; height: 45px; width: 54px; border: 10px solid #F57C00; border-bottom: 0; position: absolute; border-radius: 27px 27px 0 0; left: 48px; z-index: 1001; top: 20px; }
同樣是設(shè)置圓角
.container>.logo>.logo-block-bottom { position: absolute; height: 60px; width: 80px; box-sizing: border-box; background-color: #FFA000; z-index: 1001; top: 65px; left: 35px; border-radius: 7px; }
設(shè)置鑰匙心,這個(gè)也分為兩部分,上面的圓孔和和下面的橢圓
剛好可以設(shè)置在 lock-bottom 的 before和after偽元素上面
.container>.logo>.logo-block-bottom::before { content: " "; position: absolute; height: 12px; width: 12px; background-color: #EFEFEF; border-radius: 5px; top: 22px; left: 34px; box-sizing: border-box; } .container>.logo>.logo-block-bottom::after { content: " "; position: absolute; height: 12px; width: 6px; background-color: #EFEFEF; border-radius: 2px; top: 30px; left: 37px; box-sizing: border-box; }
到這里 logo 就完成了
下面是 ' 用戶登錄 ' 標(biāo)題.
注意,這里好使用margin 而不是padding,不要破壞原有h5 標(biāo)簽.
.container>.login-header { text-align: center; font-size: 23px; color: #FF4081; font-weight: 400; margin: 15px 0 18px 0; }
為內(nèi)容添加一個(gè)容器
.container>.content { width: 90%; margin: 0 auto; }
添加一個(gè) form-group,包含 label和input 標(biāo)簽,設(shè)置相對(duì)布局
.container>.content>.form-group { position: relative; }
下面就是核心部分,為input 設(shè)置樣式(這里會(huì)產(chǎn)生一個(gè)bug,在結(jié)尾會(huì)介紹)
.container>.content>.form-group>.form-control { z-index: 3; position: relative; height: 58px; width: 100%; border: 0px; border-bottom: 1px solid #777; padding-top: 22px; color: #FF4081; font-size: 12px; background: none; box-sizing: border-box; outline: none; display: inline-block; -webkit-transition: 0.3s; transition: 0.3s; }
labe 標(biāo)簽,使用絕對(duì)定位,將其放置到Input的上面.
.container>.content>.form-group>.form-label { z-index: 1; position: absolute; bottom: 10px; left: 0; font-size: 15px; -webkit-transition: 0.3s; transition: 0.3s; }
為兩個(gè)form group 設(shè)置一定的間距,否則下面會(huì)擋住上面設(shè)置的 box-shadow
.container>.content>.form-group>:first-child { margin-bottom: 5px; }
添加動(dòng)態(tài)效果
.container>.content>.form-group>.form-control:focus, .container>.content>.form-group>.form-control:valid { box-shadow: 0 1px #FF4081; border-color: #FF4081; } .container>.content>.form-group>.form-control:focus+.form-label, .container>.content>.form-group>.form-control:valid+.form-label { font-size: 12px; -ms-transform: translateY(-20px); -webkit-transform: translateY(-20px); transform: translateY(-25px); }
下面就到了底部option ,也分為兩部分,option-left 和 option-right
.container>.content>.option { width: 100%; height: 14px; margin-top: 24px; font-size: 16px; } .container>.content>.option>.option-left { width: 50%; float: left; } .container>.content>.option>.option-left>a, .container>.content>.option>.option-left>a:hover { color: #FF4081; text-decoration: none; }
在option-right 中,要注意 這個(gè)復(fù)選框并不是原生的Input,而是使用div 旋轉(zhuǎn)而得,因?yàn)樵腸heckbox無法更改樣式.
.container>.content>.option>.option-right { width: 50%; float: right; text-align: right; position: relative; } .container>.content>.option>.option-right>.md-checkbox { height: 18px; width: 18px; display: inline-block; box-sizing: border-box; position: absolute; background-color: #FF4081; cursor: pointer; position: absolute; top: 3px; right: 68px; } .container>.content>.option>.option-right>.md-checkbox[checked]:after { content: " "; border-left: 2px solid #fff; border-bottom: 2px solid #fff; height: 8px; width: 15px; box-sizing: border-box; position: absolute; transform: rotate(-45deg); top: 3px; left: 2px; }
這里使用css3 中的旋轉(zhuǎn),而模仿一個(gè)選中效果
注意: 雖然div無法直接選中,但還是可以為其添加一個(gè)checkd屬性, 這個(gè)屬性是一個(gè)特殊的css 事件效果,可以通過js來控制.
最后,登錄按鈕.
這里,也必須使用絕對(duì)定位,參照點(diǎn)是bottom和right
.container>.login-button { position: absolute; height: 60px; width: 60px; border: 0px; outline: 0px; background-color: #FF4081; border-radius: 30px; right: -30px; bottom: 91px; box-shadow: 2px 0 0 rgba(0, 0, 0, 0.3) inset; }
通過 box-shadow: 2px 0 0 rgba(0, 0, 0, 0.3) inset; 這句話可以知道一個(gè)內(nèi)嵌效果.
中間的按鈕在不適用字體圖標(biāo)的情況下也必須要用div 旋轉(zhuǎn)來模仿了
.container>.login-button >.icon-login { box-sizing: border-box; position: relative; width: 18px; height: 3px; background-color: #fff; transition: 0.3s; display: block; margin: auto; } .container>.login-button >.icon-login::after { content: ' '; box-sizing: border-box; position: absolute; left: 8px; height: 12px; width: 12px; border-top: 3px solid #fff; border-right: 3px solid #fff; transform: rotate(45deg); top: -4px; }
最后是鼠標(biāo)hover上的放大和陰影效果
.container>.login-button:hover { box-shadow: 0 0 0 rgba(0, 0, 0, 0.3) inset, 0 3px 6px rgba(0, 0, 0, 0.16), 0 5px 11px rgba(0, 0, 0, 0.23) } .container>.login-button:hover>.icon-login { -ms-transform: scale(1.2); =webkit-transform: scale(1.2); transform: scale(1.2); }
至此,所有的css已經(jīng)結(jié)束了,查看效果
transition bug修復(fù)
當(dāng)我刷新頁面或者點(diǎn)擊忘記密碼的時(shí)候,input框就會(huì)抖動(dòng)一下,這個(gè)問題只會(huì)出現(xiàn)在chrome 瀏覽器上,firefox 或者edge都不會(huì)重現(xiàn),所以我才這應(yīng)該是兼容性的問題。 在不斷嘗試中,我發(fā)現(xiàn),只有取消 transition屬性,就不會(huì)產(chǎn)生抖動(dòng)。
這個(gè)問題困擾了我3天,真實(shí)百思不得其姐。
在某度中查詢半天,未果 。
后來終于在 StackOverFlow 中,搜索chrome input transition 時(shí),終于一個(gè)回到讓我貌似頓開。
this bug has been reported, adding an script tag somewhere can advoid it.
之后,我在頁面尾部添加一個(gè)下面節(jié)點(diǎn),終于順利解決。
在閱讀過一些文章之后,總結(jié)為
當(dāng)chrome 的input 默認(rèn)屬性向自定義過度時(shí),因?yàn)榇嬖趖ransition,所以會(huì)產(chǎn)生抖動(dòng)。 而基本上所有的頁面都有script標(biāo)簽,所以這個(gè)bug 幾乎很難被重現(xiàn)。而我遇到,算是運(yùn)氣好吧。。
至此,這個(gè)頁面全部?jī)?nèi)容已經(jīng)完成。
material-design 很贊,angular-material 是使用 AngularJS 封裝了 material-design 的UI 庫,很漂亮。不同于 bootstrap的完全扁平化風(fēng)格,它采用的是盒子堆砌效果,動(dòng)畫效果也比較贊。
關(guān)于“如何使用CSS3制作一個(gè)material-design 風(fēng)格登錄界面”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。
網(wǎng)頁名稱:如何使用CSS3制作一個(gè)material-design風(fēng)格登錄界面-創(chuàng)新互聯(lián)
當(dāng)前URL:http://fisionsoft.com.cn/article/ceoicg.html