25 心形按钮

news2024/9/20 10:56:12

效果演示

14-心形按钮.gif

实现了一个心形的心形图案,当用户点击图案时,图案会旋转并缩小,同时背景颜色会变成白色。

Code

<div class="love">
  <input id="switch" type="checkbox">
  <label class="love-heart" for="switch">
    <i class="left"></i>
    <i class="right"></i>
    <i class="bottom"></i>
    <div class="round"></div>
  </label>
</div>
body {
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #212121;
}

.love-heart:before,
#switch {
    display: none;
}

.love-heart,
.love-heart::after {
    border-color: hsl(231deg 28% 86%);
    border: 1px solid;
    border-top-left-radius: 100px;
    border-top-right-radius: 100px;
    width: 10px;
    height: 8px;
    border-bottom: 0
}

.round {
    position: absolute;
    z-index: 1;
    width: 8px;
    height: 8px;
    background: hsl(0deg 0% 100%);
    box-shadow: rgb(0 0 0 / 24%) 0px 0px 4px 0px;
    border-radius: 100%;
    left: 0px;
    bottom: -1px;
    transition: all .5s ease;
    animation: check-animation2 .5s forwards;
}

input:checked+label .round {
    transform: translate(0px, 0px);
    animation: check-animation .5s forwards;
    background-color: hsl(0deg 0% 100%);
}

@keyframes check-animation {
    0% {
        transform: translate(0px, 0px);
    }

    50% {
        transform: translate(0px, 7px);
    }

    100% {
        transform: translate(7px, 7px);
    }
}

@keyframes check-animation2 {
    0% {
        transform: translate(7px, 7px);
    }

    50% {
        transform: translate(0px, 7px);
    }

    100% {
        transform: translate(0px, 0px);
    }
}

.love-heart {
    box-sizing: border-box;
    position: relative;
    transform: rotate(-45deg) translate(-50%, -33px) scale(4);
    display: block;
    border-color: hsl(231deg 28% 86%);
    cursor: pointer;
    top: 0;
}

input:checked+.love-heart,
input:checked+.love-heart::after,
input:checked+.love-heart .bottom {
    border-color: hsl(347deg 81% 61%);
    box-shadow: inset 6px -5px 0px 2px hsl(347deg 99% 72%);
}

.love-heart::after,
.love-heart .bottom {
    content: "";
    display: block;
    box-sizing: border-box;
    position: absolute;
    border-color: hsl(231deg 28% 86%);
}

.love-heart::after {
    right: -9px;
    transform: rotate(90deg);
    top: 7px;
}

.love-heart .bottom {
    width: 11px;
    height: 11px;
    border-left: 1px solid;
    border-bottom: 1px solid;
    border-color: hsl(231deg 28% 86%);
    left: -1px;
    top: 5px;
    border-radius: 0px 0px 0px 5px;
}

实现思路拆分

cbody {
  height: 100vh; /* 设置页面高度为视口高度 */
  display: flex; /* 设置页面布局为弹性布局 */
  justify-content: center; /* 设置主轴对齐方式为居中对齐 */
  align-items: center; /* 设置交叉轴对齐方式为居中对齐 */
  background-color: #212121; /* 设置背景颜色为深灰色 */
}

这段代码设置了页面的基本样式,包括高度、布局、对齐方式和背景颜色。

.love-heart:before,
#switch {
  display: none; /* 隐藏元素 */
}

这段代码隐藏了 .love-heart:before#switch 两个元素。

.love-heart,
.love-heart::after {
  border-color: hsl(231deg 28% 86%); /* 设置边框颜色为深黄色 */
  border: 1px solid; /* 设置边框为实线 */
  border-top-left-radius: 100px; /* 设置左上角圆角半径为 100px */
  border-top-right-radius: 100px; /* 设置右上角圆角半径为 100px */
  width: 10px; /* 设置宽度为 10px */
  height: 8px; /* 设置高度为 8px */
  border-bottom: 0 /* 隐藏底部边框 */
}

这段代码设置了 .love-heart.love-heart::after 两个元素的样式,包括边框颜色、边框、圆角半径、宽度、高度和底部边框。

.round {
  position: absolute; /* 设置元素的定位方式为绝对定位 */
  z-index: 1; /* 设置元素的堆叠顺序为最高 */
  width: 8px; /* 设置元素的宽度为 8px */
  height: 8px; /* 设置元素的高度为 8px */
  background: hsl(0deg 0% 100%); /* 设置元素的背景颜色为白色 */
  box-shadow: rgb(0 0 0 / 24%) 0px 0px 4px 0px; /* 设置元素的阴影效果 */
  border-radius: 100%; /* 设置元素的圆角半径为 100% */
  left: 0px; /* 设置元素的左边距为 0px */
  bottom: -1px; /* 设置元素的底部边距为 -1px */
  transition: all.5s ease; /* 设置元素的过渡效果 */
  animation: check-animation2.5s forwards; /* 设置元素的动画效果 */
}

这段代码设置了 .round 元素的样式,包括定位方式、堆叠顺序、宽度、高度、背景颜色、阴影效果、圆角半径、左边距、底部边距、过渡效果和动画效果。

input:checked+label.round {
  transform: translate(0px, 0px); /* 移动元素 */
  animation: check-animation.5s forwards; /* 执行动画 */
  background-color: hsl(0deg 0% 100%); /* 设置背景颜色为白色 */
}

这段代码设置了 :checked 状态下的 .round 元素的样式,包括移动元素、执行动画和背景颜色。

@keyframes check-animation {
  0% {
    transform: translate(0px, 0px); /* 元素初始状态 */
  }

  50% {
    transform: translate(0px, 7px); /* 元素动画过程 */
  }

  100% {
    transform: translate(7px, 7px); /* 元素最终状态 */
  }
}

这段代码定义了一个名为 check-animation 的动画效果,包括元素的初始状态、动画过程和最终状态。

.love-heart {
  box-sizing: border-box; /* 设置盒模型为 border-box */
  position: relative; /* 设置定位为相对定位 */
  transform: rotate(-45deg) translate(-50%, -33px) scale(4); /* 旋转 -45 度,平移 -50% -33px,缩放 4 倍 */
  display: block; /* 设置显示为块级元素 */
  border-color: hsl(231deg 28% 86%); /* 边框颜色 */
  cursor: pointer; /* 光标类型为指针 */
  top: 0; /* 上侧偏移量为 0 */
}

这段代码设置了 .love-heart 元素的样式,包括盒模型、定位、旋转、缩放、显示、边框颜色、光标类型和上侧偏移量。

input:checked+.love-heart,
input:checked+.love-heart::after,
input:checked+.love-heart.bottom {
  border-color: hsl(347deg 81% 61%); /* 边框颜色 */
  box-shadow: inset 6px -5px 0px 2px hsl(347deg 99% 72%); /* 阴影效果 */
}

这段代码设置了 :checked 状态下的 .love-heart 元素和 .love-heart::after 元素的样式,包括边框颜色和阴影效果。

.love-heart::after,
.love-heart.bottom {
  content: ""; /* 内容为空 */
  display: block; /* 显示为块级元素 */
  box-sizing: border-box; /* 设置盒模型为 border-box */
  position: absolute; /* 定位为绝对定位 */
  border-color: hsl(231deg 28% 86%); /* 边框颜色 */
}

这段代码设置了 .love-heart::after.love-heart.bottom 元素的样式,包括内容、显示方式、盒模型、定位、边框颜色。

.love-heart::after {
  right: -9px; /* 右侧偏移量 */
  transform: rotate(90deg); /* 旋转 90 度 */
  top: 7px; /* 上侧偏移量 */
}

这段代码设置了 .love-heart::after 元素的样式,包括右侧偏移量、旋转角度和上侧偏移量。

.love-heart.bottom {
  width: 11px; /* 宽度为 11px */
  height: 11px; /* 高度为 11px */
  border-left: 1px solid; /* 左侧边框为实线 */
  border-bottom: 1px solid; /* 下侧边框为实线 */
  border-color: hsl(231deg 28% 86%); /* 边框颜色 */
  left: -1px; /* 左侧偏移量 */
  top: 5px; /* 上侧偏移量 */
  border-radius: 0px 0px 0px 5px; /* 左上角圆角半径为 0px,右上角圆角半径为 5px */
}

这段代码设置了 .love-heart.bottom 元素的样式,包括宽度、高度、左侧边框、下侧边框、边框颜色、左侧偏移量、上侧偏移量和圆角半径。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1367683.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

窗口超出屏幕拉不出来或移到屏幕边上的解决办法

前言 由于一些原因&#xff0c;比如进行远程电脑时屏幕大小不同&#xff0c;导致一些程序窗口超出屏幕拉不出来或移到屏幕边上&#xff0c; 我是在公司有个大屏幕&#xff0c;抱着笔记本回去之后&#xff0c;有个软件打开之后啥也没有。估计是跑到屏幕外了。 以下附上解决方法…

软件工程概论---内聚性和耦合性

目录 一.耦合性 1.内容耦合 2.公共耦合 4.控制耦合 5.标记耦合&#xff08;特征耦合&#xff09; 6.数据耦合 7.非直接耦合 二.内聚性 1.偶然内聚 2.逻辑内聚 3.时间内聚 4.过程内聚 5.通信内聚 6.顺序内聚 7.功能内聚 一.耦合性 耦合性是指软件结构中模块相互…

React 类组件和函数组件

组件component 一.概念 Element VS Component (元素与组件) //不成文的约定:元素小写&#xff0c;组件大写 const divReact.createElement(div,...) 这是一个React元素(小写) const Div()>React.createElement(div,...) 这是一个React组件(大写) 什么是组件? 能跟其他…

解决:已经安装open3d,还是报错No module named ‘open3d‘的问题

首先示例&#xff0c;我是如何安装又是如何被报错的过程。 报错过程&#xff1a; 网上普遍的安装指令就是下面这个&#xff1a; pip install open3d 我是直接python页面的终端安装的&#xff1a; 安装完&#xff0c;检查列表已安装文件是否有open3d&#xff0c; 输入指令 …

Linux:进程的通信

目录 进程间的通信 管道 1.概念 2.匿名管道 3.命名管道 4.匿名管道与命名管道的区别 5.总结管道的特点 共享内存 1.原理 2.共享内存的建立 3.代码 1.相关函数 2.总结 进程间的通信 1.进程间通信目的 数据传输&#xff1a;一个进程需要将它的数据发送给另一个进程…

flex弹性盒子常用的布局属性详解

想必大家在开发中经常会用到flex布局。而且还会经常用到 justify-content 属性实现分栏等等 接下来给大家分别讲一下 justify-content 的属性值。 以下是我敲的效果图大家可以清晰看出区别 space-between 属性值可以就是说两端对齐 space-evenly 属性值是每个盒子之间的…

攀登者1 - 华为OD统一考试

OD统一考试 分值: 100分 题解: Java / Python / C++ 题目描述 攀登者喜欢寻找各种地图,并且尝试攀登到最高的山峰。 地图表示为一维数组,数组的索引代表水平位置,数组的元素代表相对海拔高度。其中数组元素0代表地面。 例如:[0,1,2,4,3,1,0,0,1,2,3,1,2,1,0],代表如下…

如何顺滑使用华为云编译构建平台?

这两年平台构建服务需求越来越大&#xff0c;却一直苦于找不到一些指南&#xff0c; 这里特意写了一篇&#xff0c; 对在学习代码阶段和新手程序员朋友也蛮友好&#xff0c; 配置真的也不难&#xff0c; 也特别适合想尝试从0到1做个APP的朋友了。 以华为云的CodeArts Build为例…

鸿蒙系统应用开发之开发准备

今天我们来聊一聊鸿蒙系统应用开发之前&#xff0c;要做什么准备工作&#xff0c;如下图所示&#xff0c;我们要做的就是安装DevEco Studio&#xff0c;然后配置开发环境。 老规矩&#xff0c;拍拍手&#x1f44f;&#xff0c;上菜。 安装DevEco Studio 首先我们打开链接HUAWEI…

【Linux Shell】12. 文件包含

和其他语言一样&#xff0c;Shell 也可以包含外部脚本&#xff0c;这样可以很方便的封装一些公用的代码作为一个独立的文件。可以理解为在第2个文件中包含第1个文件&#xff0c;执行第1个文件的代码。 被包含的文件 不需要可执行权限 。Shell 文件包含的语法格式如下&#xff1…

Git将本地项目上传到Gitee仓库

1.右键点击文件&#xff0c;点击Git Bash Here,进入git窗口 2.初始化本地仓库 git init3.将本地仓库与远程仓库建立连接 git remote add origin 远程仓库地址远程仓库地址在gitee仓库复制即可 4.将远程仓库的文件拉到本地仓库中 git pull origin master5.将本地文件全部上传…

探索C语言中的水仙花数及其计算方法

在计算机科学与数学的交叉领域中&#xff0c;有一种特殊的整数被称为“水仙花数”&#xff0c;它是指一个三位数&#xff0c;其各位数字立方和等于该数本身。例如&#xff0c;153是一个典型的水仙花数&#xff0c;因为1 5 3 1 125 27 153。 下面&#xff0c;我们通过一段…

0_项目git地址——正点原子minifly与crazyflie

1、说明&#xff1a; 在每个专栏的第一篇文章&#xff0c;笔者都会贴出项目的git地址&#xff0c;方便后来者学习和复现&#xff1b; 下面介绍两个项目的官网资料和git地址&#xff0c;最后给出两者的对比&#xff1b; 2、正点原子minifly (1)minifly官网资料下载中心&#…

【sgPasswordInput】自定义组件:带前端校验密码强度的密码输入框,能够提供密码强度颜色提示和文字提示

特性&#xff1a; 有密码强度颜色提示密码强度进度条提示支持设置默认输入提示和密码长度 sgPasswordInput源码 <template><div :class"$options.name" style"width: 100%"><el-inputstyle"width: 100%"ref"psw"type&…

untiy使用http下载资源

文章目录 提醒下载一个资源并保存到本地下载一张图片 提醒 部分API需要将Unity的 Edit/PrejectSetting/Player/OtherSetttings/AConfiguration/ApiCompatibilityLevel 设为.NetFramework 才可以使用 下载一个资源并保存到本地 private IEnumerator DownloadFormServer_IE(st…

后端 API 接口文档 Swagger 使用

Swagger 是什么 swagger是一款可以根据 restful 风格生成的接口开发文档&#xff0c;并且支持做测试的一款中间软件。 例如当我们在开发前后端分离项目时&#xff0c;当后端开发完一个功能想要测试时&#xff0c;若此时还没有相应的前端页面发起请求&#xff0c;可以通过 swag…

大数据Doris(五十二):SQL函数之数学函数

文章目录 SQL函数之数学函数 一、abs(double a)

软件测试大作业||测试计划+测试用例+性能用例+自动化用例+测试报告

xxx学院 2023—2024 学年度第二学期期末考试 《软件测试》&#xff08;A&#xff09;试题&#xff08;开卷&#xff09; 题目&#xff1a;以某一 web 系统为测试对象&#xff0c;完成以下文档的编写&#xff1a; &#xff08;满分 100 分&#xff09; &#xff08;1&am…

1.6PTA集练7-5~7-24、7-1、7-2,堆的操作,部落冲突(二分查找)

7-5 大師と仙人との奇遇 分数 20 #include<iostream> #include<queue> using namespace std; int n; long long ans0,num; priority_queue<long long,vector<long long>,greater<long long>>q;//记录之前买的,用小顶堆&#xff0c;最上面就是最…

c++学习:STL库(框架)+字符串模板类string+vector容器+list链表

目录 stl库 常用组件包括 字符串库 字符串模板类string 头文件 最常用的字符串模板类 字符串类型 模板原型 模板的成员数据类型 模板成员函数 有些函数会有重载&#xff0c;可以去下面网址查看std::basic_string - cppreference.comhttps://zh.cppreference.com/w/cp…