css transition实现边框动画效果

本文详细介绍如何使用CSS伪类:focus-within实现动画效果,从边框底部中间开始,向两边延伸,通过LESS预处理器语言编写,适用于Vue.js组件。文章深入讲解了代码实现细节,包括过渡效果和颜色变化。

1. 动画从边框底部中间开始,向两边延伸,代码如下,

<template>
  <div class="hello">
    <div :class="css.aaa">
      <input type="text">
    </div>

  </div>
</template>

<script>
export default {
  name: "HelloWorld",
  props: {
    msg: String
  }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style module='css' lang="less">
.aaa {
  position: relative;
  width: 200px;
  height: 100px;
  background: red;
  padding: 0px;
  &:after {
    content: "";
    position: absolute;
    bottom: -1px;
    left: 50%;
    width: 0;
    height: 0;
    border-bottom: 2px solid transparent;
    transition: 800ms ease-out;
  }
  &:focus-within {
    background: #000;
    &:after {
      width: 100%;
      left: 0;
      border-bottom-width: 2px;
      border-bottom-color: blue;
    }
  }
}
</style>

关键部分:

focus-within   伪类:如果元素里面的元素聚焦了,就会有这个伪类

评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值