CSS3製作粉紅色登入介面

來源:互聯網
上載者:User
這次給大家帶來CSS3製作粉紅色登入介面,CSS3製作粉紅色登入介面的注意事項有哪些,下面就是實戰案例,一起來看一下。

心血來潮,想學學 material design 的設計風格,就嘗試完成了一個登入頁面製作.

這是整體效果.

感覺還不錯吧,結尾會附上代碼

在編寫的過程中,沒有使用任何圖片或者字型表徵圖,全部使用css3完成,還是遇到一些痛點和bug,所以想筆記下來,以後方便查閱.

響應式設計

在這個頁面中,使用下面3點來完成響應式設計

1、最大寬度 .設定了一個 max-width 的最大寬度,以便在大螢幕時相容.

2、margin : 20px auto; 使其保持時刻置中

3、組件使用像素

關於響應式的設計要點還有很多。

整體頁面配置

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>Document</title>    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">    <meta name="viewport" content="width=device-width, initial-scale=1.0">    <link rel="stylesheet" href="styles/style.css"></head><body>    <p class="container">        <p class="logo">            <p class="logo-block-top">            </p>            <p class="logo-block-bottom">            </p>        </p>        <h4 class="login-header">使用者登入</h4>        <p class="content">            <p class="form-group">                <input type="text" required class="form-control">                <label class="form-label">使用者名稱</label>            </p>            <p class="form-group">                <input type="text" required class="form-control">                <label class="form-label">密 碼</label>            </p>            <p class="option">                <p class="option-left"><a href="">忘記密碼</a></p>                <p class="option-right">                    <span class="md-checkbox" checked="checked"></span>                    <label class="form-label">記住密碼</label>                </p>            </p>        </p>        <button class="login-button">            <span class="icon-login"></span>        </button>    </p></body><script src="./app.js type=" text/javascript "></script></html>

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;}

注意,這裡調整內部邊距使用了padding 而不是對子項目使用margin,因為如果要使用margin,為了BFC 的效果,就需要加上 overflow: hidden. 這樣就會對尾部按鈕溢出產生影響.

頭部logo

.container>.logo {    height: 150px;    width: 150px;    position: relative;    background-color: #EFEFEF;    border-radius: 75px;    margin: 0 auto;}

設定 border-radius 為 width和height的一般,就會使其成為一個圓

下面需要一個顏色更深的半圓

如何繪製一個半圓?

.container>.logo::after {    content: ' ';    height: 150px;    width: 75px;    position: absolute;    background-color: #E1E1E1;    border-radius: 0 75px 75px 0;    left: 75px;    top: 0;}

設定寬度為高度的一般,然後設定左上方和左下角圓角為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;}

同樣是設定圓角

.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;}

設定鑰匙心,這個也分為兩部分,上面的圓孔和和下面的橢圓

剛好可以設定在 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 就完成了

下面是 ' 使用者登入 ' 標題.

注意,這裡最好使用margin 而不是padding,不要破壞原有h4 標籤.

.container>.login-header {    text-align: center;    font-size: 23px;    color: #FF4081;    font-weight: 400;    margin: 15px 0 18px 0;}

為內容添加一個容器

.container>.content {    width: 90%;    margin: 0 auto;}

添加一個 form-group,包含 label和input 標籤,設定相對布局

.container>.content>.form-group {    position: relative;}

下面就是核心部分,為input 設定樣式(這裡會產生一個bug,在結尾會介紹)

.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 標籤,使用絕對位置,將其放置到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;}

為兩個form group 設定一定的間距,否則下面會擋住上面設定的 box-shadow

.container>.content>.form-group>:first-child {    margin-bottom: 5px;}

添加動態效果

.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 中,要注意 這個複選框並不是原生的Input,而是使用p 旋轉而得,因為原生的checkbox無法更改樣式.

.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 中的旋轉,而模仿一個選中效果

注意: 雖然p無法直接選中,但還是可以為其添加一個checkd屬性, 這個屬性是一個特殊的css 事件效果,可以通過js來控制.

最後,登入按鈕.

這裡,也必須使用絕對位置,參照點是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; 這句話可以知道一個內嵌效果.

中間的按鈕在不適用字型表徵圖的情況下也必須要用p 旋轉來模仿了

.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;}

最後是滑鼠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已經結束了,查看效果

transition bug修複

當我重新整理頁面或者點擊忘記密碼的時候,input框就會抖動一下,這個問題只會出現在chrome 瀏覽器上,firefox 或者edge都不會重現,所以我才這應該是相容性的問題。 在不斷嘗試中,我發現,只有取消 transition屬性,就不會產生抖動。

這個問題困擾了我3天,真實百思不得其姐。

在某度中查詢半天,未果 。

後來終於在 StackOverFlow 中,搜尋chrome input transition 時,終於一個回到讓我貌似頓開。

this bug has been reported, adding an script tag somewhere can advoid it.

之後,我在頁面尾部添加一個下面節點,終於順利解決。

<script src="./app.js type=" text/javascript "></script>

在閱讀過一些文章之後,總結為

當chrome 的input 預設屬性向自訂過度時,因為存在transition,所以會產生抖動。 而基本上所有的頁面都有script標籤,所以這個bug 幾乎很難被重現。而我遇到,算是運氣好吧。。

至此,這個頁面全部內容已經完成。

material-design 很贊,angular-material 是使用 AngularJS 封裝了 material-design 的UI 庫,很漂亮。不同於 bootstrap的完全扁平化風格,它採用的是盒子堆砌效果,動畫效果也比較贊。

相信看了本文案例你已經掌握了方法,更多精彩請關注php中文網其它相關文章!

推薦閱讀:

CSS3實現扇形動畫菜單流程詳解

單選、複選樣式美化的圖文詳解

相關文章

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.