0
点赞
收藏
分享

微信扫一扫

渐变流光按钮练习总结

君心浅语 2022-03-11 阅读 44
csscss3html

渐变流光按钮练习总结

模块居中

/*块级元素通过margin值设置水平居中*/
div {
	width: 100px;
	margin: 0 auto;
}

/*与绝对定位配合*/
div {
	position: absolute;
	width: 100px;
	height: 50px;
	left: 50%;
	margin-left: -50px;
}

/*行内元素,在父级标签加text-aline: center;
1.left: 50%
2.margin 自己盒子走一半 负值
*/
.father {
	text-align: center;
}

通过绝对定位设置居中

/*纯绝对定位写法*/
div {
	position: absolute;
    width: 100px;
    height: 50px;
    left: calc(50% - 50px); /*calc(50% - 盒子宽度的一半)*/
    top: calc(50% - 25px); /*calc(50% - 盒子高度的一半)*/
}

颜色渐变

创建一个线性渐变,需要指定两种颜色,还可以实现不同方向(指定为一个角度)的渐变效果,如果不指定方向,默认从上到下渐变

/* 从上到下,蓝色渐变到红色 */
background: linear-gradient(blue, red);
 
/* 渐变轴为45度,从蓝色渐变到红色 */
background: linear-gradient(45deg, blue, red);
 
/* 从右下到左上、从蓝色渐变到红色 */
background: linear-gradient(to left top, blue, red);
 
/* 从下到上,从蓝色开始渐变、到高度40%位置是绿色渐变开始、最后以红色结束 */
background: linear-gradient(0deg, blue, green 40%, red);

可通过检查(F12)进行调试
渐变角度滚轮

快速创建包裹元素

<div id="warp">我要包裹它</div>
	#warp {
      position: relative;
      width: 100px;
      height: 50px;
      text-align: center;
      line-height: 50px;
      background-color: pink;
    }
	
	/*利用伪类选择器*/
    #warp::before {
      position: absolute;
      content: "";
      top: -5px;
      right: -5px;
      bottom: -5px;
      left: -5px;
      border: 1px solid red;
    }

在这里插入图片描述

滤镜

函数方法的描述

/*常用高斯模糊如果没有设定值,则默认是0;
这个参数可设置css长度值,但不接受百分比值。*/
filter: blur(20px);

动画帧

/*定义关键帧*/
@keyframes sun {
	100% {
		background-position: -400%;
	}
}

/*如何使用*/
animation: sun 8s infinite;
/*从左边到右边 帧名称 
持续时间 何时开始 播放次数 
是否反方向 动画起始和结束状态*/

渐变流光按钮总代码

<!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>渐变按钮</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    body {
      background-color: #000;
    }

    a {
      text-decoration: none;
      position: absolute;
      left: 50%;
      top: 50%;
      transform: translate(-50%, -50%);
      font-size: 24px;
      background: linear-gradient(90deg, #03a9f4, #f441a5, #ffeb3d, #03a9f4);
      background-size: 400%;
      width: 400px;
      height: 100px;
      text-align: center;
      line-height: 100px;
      text-transform: uppercase;
      color: #fff;
      border-radius: 50px;
      z-index: 1;
    }

    a::before {
      content: "";
      position: absolute;
      left: -5px;
      right: -5px;
      top: -5px;
      bottom: -5px;
      background: linear-gradient(90deg, #03a9f4, #f441a5, #ffeb3d, #03a9f4);
      background-size: 400%;
      border-radius: 50px;
      filter: blur(20px);
      z-index: -1;
    }

    a:hover::before {
      animation: sun 8s infinite;
    }

    a:hover {
      animation: sun 8s infinite;
    }

    @keyframes sun {
      100% {
        background-position: -400%;
      }
    }
  </style>
</head>

<body>
  <a href="javascript:;">sunbutton</a>
</body>

</html>
举报

相关推荐

0 条评论