(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标签为合法输入时启动样式表
发布了19 篇原创文章 · 获赞 4 · 访问量 546

猜你喜欢

转载自blog.csdn.net/zhuangww05/article/details/104272650