前言:哈喽,大家好,今天给大家分享html+css 绚丽效果!并提供具体代码帮助大家深入理解,彻底掌握!创作不易,如果能帮助到大家或者给大家一些灵感和启发,欢迎收藏+关注哦 💕
一、效果
二、原理解析
1.这是一个,hover时2边边框生长的按钮。每个按钮都是由4部分组成,button,button:before,button:after、文字,如下图。
1.1 button是最外层的。
1.2 button:before是左上角的2个边框。
width: 40px;
height: 40px;
1.3 button:after是右下角的2边框。
width: 40px;
height: 40px;
1.4 内容文字在最上层。用来显示按钮的文字。
1.5 按钮组成关系。
2.当按钮上有鼠标时,hover效果触发,运行transition过渡动画效果。
/*当hover时*/
.but2Grow:hover:before,
.but2Grow:hover:after {
width: 100%;
height: 100%;
}
3.具体的变换参数,直接看代码,可以一键复制,查看效果
三、上代码,可以直接复制使用
目录
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>html+css 实现hover边框2边生长按钮</title>
<link rel="stylesheet" href="./style.css">
</head>
<body>
<div class="container">
<h1 style="text-align: center;color:#fff;margin-bottom: 50px;padding-top: 50px; text-shadow: 0 3px 3px #4c6ed3;">
html+css 实现hover边框2边生长按钮</h1>
<div class="wrapper">
<button class="but2Grow">求点赞</button>
<button class="but2Grow">求关注</button>
<button class="but2Grow">求收藏</button>
<button class="but2Grow">求转发</button>
</div>
</div>
</body>
</html>
css
*
{
margin: 0;
padding: 0;
box-sizing: border-box;
}
:root
{
--btn-bg-color:#fff;
--font-color-black: #000;
--btn-bg-color-hover: #FF5833;
}
.container{
min-height: 100vh;
background-color: #0e1538;
}
.wrapper{
display: flex;
flex-direction: column;
align-items: center;
gap:40px;
}
.but2Grow {
color: #fff;
font-size: 1.2rem;
padding: 1em 2.5em;
background-color: #2874a6;
cursor: pointer;
position: relative;
border: none;
}
.but2Grow::before {
content: '';
position: absolute;
left: -10px;
top: -10px;
width: 40px;
height: 40px;
/* background: #2e86c1;
border: 5px solid #2e86c1; */
border-top: 5px solid #2e86c1;
border-left: 5px solid #2e86c1;
transition: all 0.4s;
}
.but2Grow::after {
content: '';
position: absolute;
bottom: -10px;
right: -10px;
width: 40px;
height: 40px;
/* background: #2e86c1;
border: 5px solid #2e86c1; */
border-bottom: 5px solid #2e86c1;
border-right: 5px solid #2e86c1;
transition: all 0.4s;
}
/*当hover时*/
.but2Grow:hover:before,
.but2Grow:hover:after {
width: 100%;
height: 100%;
}
到此这篇文章就介绍到这了,更多精彩内容请关注本人以前的文章或继续浏览下面的文章,创作不易,如果能帮助到大家,希望大家多多支持宝码香车~💕
更多专栏订阅推荐:
👍 html+css+js 绚丽效果
💕 vue
✈️ Electron
⭐️ js
📝 字符串
✍️ 时间对象(Date())操作