(Html+Css筆記)高端大氣簡潔的網頁登錄界面

在這裏插入圖片描述在這裏插入圖片描述

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
    body{
    padding: 0px;
    margin: 0px;
    background: url(background01.jpg);
    background-size: cover;
    }
    .box1{
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%,-50%);
        width: 400px;
        padding: 40px;
        background: rgb(0,0,0,0.8);
        box-sizing: border-box;
        box-shadow: 0 15px 25px rgb(0,0,0,0.5);
        border-radius: 10px;
    }
    .box1 h1{
        margin: 0 0 30px;
        padding: 0px;
        color: #ffffff;
        text-align: center;
    }
    .box1 .inputbox{
        position: relative;
    }
    .box1 .inputbox input{
        width: 100%;
        padding: 10px 0;
        margin-bottom: 30px;
        font-size: 18px;
        border: none;
        color: #ffffff;
        outline: none;
        background: transparent;
        border-bottom: 1px solid #ffffff;
    }
    .box1 .inputbox label{
        position:  absolute;
        top: 0;
        left: 0;
        font-size: 18px;
        color: #ffffff;
        pointer-events: none;
        transition: 0.5s;
    }
    .box1 .inputbox input:focus ~ label,
    .box1 .inputbox input:valid ~ label{
        top: -18px;
        left: 0px;
        font-size: 16px;
        color: #03a9f4;
    }
    .box1 input[type="submit"]{
        background: transparent;
        border: none;
        outline: none;
        color: #ffffff;
        background: #03a9f4;
        padding: 10px 20px;
        cursor: pointer;
        border-radius: 5px;
    }
    </style>
</head>
<body>
    <div class="box1">
        <h1>Login</h1>
        <form>
            <div class="inputbox">
                <input type="text" required="">
                <label>Username</label>
            </div>
            <div class="inputbox">
                <input type="password" required="">
                <label>Password</label>
            </div>
            <input type="submit" value="Submit">
        </form>
    </div>
</body>
</html>

關注點

  • input的type屬性設置爲password之後自動將字符串變爲圓點
  • 1.body的margin和padding設置爲0的目的是
    ①爲了消除各種元素自帶的margin/padding值
    ②body默認自帶8px的margin/padding值
    ③消除上述值的好處可以防止在不同瀏覽器裏的樣式表現不會有偏差
  • 居中代碼可爲{top:50%;left:50%;transform:translate(-50%,-50%);}
  • box-sizing屬性允許我們在元素的總寬度和高度中包含填充和邊框,在設置元素padding/border值的時候保持穩定的寬高
  • :valid僞類選擇器,當input標籤爲合法輸入時啓動樣式表
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章