玻璃闪烁效果3D按钮片段

在这个纯CSS代码片段中,你会看到有一个单独的按钮,并且在悬停时,它会转换为一个带有玻璃闪烁效果的3D按钮。

在这里插入图片描述

HTML代码

<div class="wrapper">
  <a href="#" class="button">Shiney!</a>
</div>

CSS代码

@keyframes sheen {
    
    
  0% {
    
    
    transform: skewY(-45deg) translateX(0);
  }
  100% {
    
    
    transform: skewY(-45deg) translateX(12.5em);
  }
}

.wrapper {
    
    
  display: block;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.button {
    
    
	padding: 0.75em 2em;
	text-align: center;
	text-decoration: none;
	color: #2194E0;
	border: 2px solid #2194E0;
	font-size: 24px;
	display: inline-block;
	border-radius: 0.3em;
	transition: all 0.2s ease-in-out;
	position: relative;
	overflow: hidden;
}

.button:before {
    
    
	content: "";
	background-color: rgba(255,255,255,0.5);
	height: 100%;
	width: 3em;
	display: block;
	position: absolute;
	top: 0;
	left: -4.5em;
	transform: skewX(-45deg) translateX(0);
	transition: none;
}

.button:hover {
    
    
	background-color: #2194E0;
    color: #fff;
    border-bottom: 4px solid darken(#2194E0, 10%);
}

.button:hover::before {
    
    
	transform: skewX(-45deg) translateX(13.5em);
    transition: all 0.5s ease-in-out;
}

SCSS代码

$color: #2194E0;

@keyframes sheen {
    
    
  0% {
    
    
    transform: skewY(-45deg) translateX(0);
  }
  100% {
    
    
    transform: skewY(-45deg) translateX(12.5em);
  }
}

.wrapper {
    
    
  display: block;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.button {
    
    
  padding: 0.75em 2em;
  text-align: center;
  text-decoration: none;
  color: $color;
  border: 2px solid $color;
  font-size: 24px;
  display: inline-block;
  border-radius: 0.3em;
  transition: all 0.2s ease-in-out;
  position: relative;
  overflow: hidden;
  &:before {
    
    
    content: "";
    background-color: rgba(255,255,255,0.5);
    height: 100%;
    width: 3em;
    display: block;
    position: absolute;
    top: 0;
    left: -4.5em;
    transform: skewX(-45deg) translateX(0);
    transition: none;
  }
  &:hover {
    
    
    background-color: $color;
    color: #fff;
    border-bottom: 4px solid darken($color, 10%);
    &:before {
    
    
      transform: skewX(-45deg) translateX(13.5em);
      transition: all 0.5s ease-in-out;
    }
  }
}

猜你喜欢

转载自blog.csdn.net/weixin_51333606/article/details/124739340