CSS也可以这么美之登录页面

前言

在前端学习中,有”三大山脉“分别是html+css+javascript相信每个学前端的小伙伴都学习过,但是很多人却都不知道用纯css也可以写出非常好看的页面来,今天写了一个简单的登录页面和各位小伙伴交流学习。

代码实现

HTML代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <!-- 引入图标和页面css文件 -->
    <link rel="stylesheet" href="icon.css">
    <link rel="stylesheet" href="login.css">
    <title>LOGIN</title>
</head>

<body>
    <div class="image">
        <!-- 图片大家可以自选电脑里任意,以写好调整图片大小css代码 -->
        <img src="./imageM.jpg" alt="">
    </div>
    <div class="login">
        <div class="header">
            LOGIN
        </div>
        <div class="input">
            <div class="input-border">
                <input type="text" class="border" name="username" placeholder="username">
            </div>
            <div class="input-border">
                <input type="password" class="border" name="password" placeholder="password">
            </div>
        </div>
        <div class="action">
            <div class="btn-login">login</div>
        </div>
        <div class="icon">
            <i class="iconfont icon-qq"></i>
            <i class="iconfont icon-weibo"></i>
            <i class="iconfont icon-weixin"></i>
        </div>
    </div>
</body>

</html>

CSS代码:

* {
    padding: 0;
    margin: 0;
}

html {
    height: 100%;
}

body {
    height: 100%;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    display: flex;
    /*实现块级元素垂直居中*/
    justify-content: center;
    align-items: center;
}

.image img {
    /*实现图片自适应屏幕大小*/
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -10;
}

.login {
    width: 300px;
    background-color: rgba(41, 45, 62, 0.7);
    color: aliceblue;
    border-radius: 8px;
    padding: 50px;
}

.login .header {
    text-align: center;
    font-size: 30px;
    line-height: 100px;
}

.login .input input {
    background-color: rgb(41, 45, 62);
    border: 0px;
    width: 100%;
    text-align: center;
    font-size: 15px;
    color: aliceblue;
    outline: none;
}

.login .input input::placeholder {
    text-transform: uppercase;
}

.login .input-border {
    /*实现颜色从左到右渐变效果*/
    background-image: linear-gradient(to right, #e8198b, #3B65BB);
    height: 45px;
    width: 100%;
    margin-bottom: 20px;
    border-radius: 25px;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: .3s;
}

.login .input-border .border {
    /*这里使用了css3的calc()方法用于自动计算宽高*/
    height: calc(100% - 4px);
    width: calc(100% - 4px);
    border-radius: 25px;
    font-size: 14px;
}

.login .btn-login {
    width: 60%;
    border: 2px solid #3B65BB;
    margin: 0 auto;
    text-align: center;
    line-height: 40px;
    text-transform: uppercase;
    border-radius: 25px;
    cursor: pointer;
    transition: .3s;
}

.login .btn-login:hover {
    background-color: #3B65BB;
}

.login .icon {
    text-align: center;
    width: 60%;
    margin: 0 auto;
    margin-top: 18px;
    border-top: 1px dashed #eee;
    padding-top: 13px;
}

.login .icon i {
    font-size: 18px;
    color: rgb(187, 187, 187);
    cursor: pointer;
    padding: 0 5px;
}

效果图:

登录页

学习总结

本次学习主要是对页面布局的练手进一步加深对前端学习的兴趣以及对css的复习。同时对比较生疏的calc()方法进行了学习。

calc()从字面我们可以把他理解为一个函数function,是css3的一个新增的功能,用来指定元素的长度。calc()最大的好处就是用在流体布局上,可以通过calc()计算动态得到元素的宽度。比如说“width:calc(50%+2em)”,这样一来你就不用考虑元素DIV的宽度值到底是多少,而把这个烦人的任务交由浏览器去计算。

calc()的运算规则

  1. 使用“+”、“-”、“*”和“/”四则运算
  2. 可以使用百分比、px、em、rem等单位
  3. 可以混合使用各种单位进行计算
  4. 表达式中有“+”和“-”时,其前后必须要有空格
  5. 表达式中有“*”和“/”时,其前后可以没有空格,但建议留有空格
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容