:focus-within 伪类小练习

 效果是点击输入框,熊猫图标会来回变化

直接上代码:

<template>
<div class="login-form">
    <h2>账密登录</h2>
    <div class="form-item form-tel">
        <input maxlength="64" placeholder="邮箱/手机号(国际号码加区号)">
        <img src="https://sf3-scmcdn2-tos.pstatp.com/xitu_juejin_web/img/greeting.1415c1c.png" class="greeting">
    </div>
    <div class="form-item form-password">
        <input class="form-password" type="password" maxlength="64" placeholder="请输入密码">
        <img src="https://sf3-scmcdn2-tos.pstatp.com/xitu_juejin_web/img/blindfold.58ce423.png" class="blindfold">
    </div>
    <img src="https://sf3-scmcdn2-tos.pstatp.com/xitu_juejin_web/img/normal.0447fe9.png" class="normal">
    <button class="btn-submit">登录</button>
</div>
</template>

<script lang="ts" setup>
</script>

<style lang='less'>
*{
    margin: 0;
    padding: 0;
}
body{
    background-color: #e9e9e9;
}
.login-form {
    width: 370px;
    margin: 100px auto;
    padding: 24px;
    background-color: #fff;
    position: relative;
    h2{
        color: #333;
        font-size: 18px;
        margin-bottom: 24px;
    }
    input {
        outline: none;
        padding: 10px;
        margin-bottom: 10px;
        width: 100%;
        border: 1px solid #e9e9e9;
        border-radius: 2px;
        box-sizing: border-box;
        font-size: 16px;
    }
    input:focus{   
        border-color: #007fff;
    }
    img{
        width: 120;
        height: 95px;
        position: absolute;
        top: 0;
        left: 50%;
        transform: translate(-50%,-50%);
    }
    .form-tel img{
        height: 113px;
    }
    .form-password img{
        width: 103px;
        height: 84px;
    }
    .form-item img{
        display: none;
    }
    .form-item:focus-within ~ img{
        display: none;
    }   
    .form-item:focus-within {   
        img {
            display: block;
        }
    }
    .btn-submit{
        width: 100%;
        height: 40px;
        color: #fff;
        background-color: #007fff;
        border-radius: 2px;
        outline: none;
        box-sizing: border-box;
        cursor: pointer;
        margin-top: 10px;
        border: none;
        padding: 8px 20px;
    }
}
</style>

 另外:

怎么让图片居中

 translate是以当前位置为原点,进行移动

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值