material文本框与按钮边框旋转效果实现登录页面

1 篇文章 0 订阅

我们总是看见一些效果比较酷炫的登录页面,那么他们是怎么实现的呢?今天我就简单的写了一个,样式比较丑,别太在意,可以自己修改样式。

效果图:

 

 html代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="./login.css"></link>
</head>
<body>
    <div class="center">
        <div class="from-item">
            <input id="username" required type="text" />
            <span class="bar"></span>
            <label for="username">User Name</label>
        </div>
        <div class="from-item">
            <input id="password" required type="text" />
            <span class="bar"></span>
            <label for="password">PassWord</label>
        </div>
        <div class="btn">
            <p>Login</p>
        </div>
    </div>
</body>
</html>

css代码:

html,
body {
    height: 100%;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.center {
    width: 400px;
    height: 300px;
    position: absolute;
    background-color: gainsboro;
}

.from-item {
    position: relative;
    width: 300px;
    margin-top: 50px;
    margin-left: 50px;
}

.from-item input {
    font-size: 18px;
    padding: 10px 10px 10px 5px;
    display: block;
    width: 300px;
    border: none;
    outline: none;
    border-bottom: 1px solid #757575;
}

.from-item label {
    position: absolute;
    color: #999;
    font-size: 18px;
    transition: 0.4s ease;
    top: 10px;
    left: 5px;
}

.from-item .bar {
    position: absolute;
    width: 0;
    height: 2px;
    bottom: 0;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #5264ae;
    transition: 0.4s ease;
}

.from-item input:focus~.bar {
    width: 100%;
}

.from-item input:valid~label,
.from-item input:focus~label {
    color: #5264ae;
    transform: translateY(-40px);
    font-size: 16px;
}

.btn {
    margin-top: 40px;
    width: 120px;
    height: 40px;
    margin-left: 35%;
    border-radius: 3px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow: hidden;
}
.btn>p{
    z-index: 5;
}
.btn::before {
    content: '';
    background: #5264ae;
    position: absolute;
    height: 200%;
    width: 200%;
    border-radius: 3px;
    animation: border-line 3s infinite linear;
    z-index: 2;
    transform-origin: 0 0;
    top: 50%;
    left: 50%;
}

@keyframes border-line {
    to {
        transform: rotate(1turn);
    }
}

.btn::after {
    content: '';
    background: #fff;
    height: calc(100% - 4px);
    width: calc(100% - 4px);
    position: absolute;
    z-index: 3;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
利用Shader实现边框效果的方法如下: 1. 创建一个新的Shader 在Unity中,可以通过在Project面板中右键点击创建一个新的Shader来创建一个新的Shader文件。 2. 编写Shader代码 在创建好的Shader文件中,可以使用Shader语言编写代码来实现边框效果。以下是一个简单的示例代码: ``` Shader "Custom/TextOutline" { Properties { _MainTex ("Texture", 2D) = "white" {} _OutlineColor ("Outline Color", Color) = (0,0,0,1) _OutlineWidth ("Outline Width", Range(0, 0.1)) = 0.005 } SubShader { Tags {"Queue"="Transparent" "RenderType"="Transparent"} Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" struct appdata { float4 vertex : POSITION; float2 uv : TEXCOORD0; }; struct v2f { float2 uv : TEXCOORD0; float4 vertex : SV_POSITION; }; sampler2D _MainTex; float4 _OutlineColor; float _OutlineWidth; v2f vert (appdata v) { v2f o; o.vertex = UnityObjectToClipPos(v.vertex); o.uv = v.uv; return o; } fixed4 frag (v2f i) : SV_Target { float4 col = tex2D(_MainTex, i.uv); float4 outline = tex2D(_MainTex, i.uv + float2(-_OutlineWidth, 0)) + tex2D(_MainTex, i.uv + float2(_OutlineWidth, 0)) + tex2D(_MainTex, i.uv + float2(0, -_OutlineWidth)) + tex2D(_MainTex, i.uv + float2(0, _OutlineWidth)); outline.a = 1.0; return lerp(outline, col, col.a); } ENDCG } } FallBack "Diffuse" } ``` 3. 将Shader应用到Text组件上 在创建好的Shader文件中,可以通过将Shader应用到Text组件的Material上来实现边框效果。具体的方法是在Project面板中选择Text组件的Material,然后将Shader设置为刚刚创建的Shader即可。 需要注意的是,以上示例代码实现边框效果比较简单,可以根据实际需求来调整代码中的参数和算法。同时,Shader的编写也需要一定的基础知识和经验。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值