前端 CSS : 2# 纯 CSS 实现多彩的 Buttons(box-shadow)

算法踏风人
• 阅读 1835

介绍

box-shadow 介绍

中国色

感謝 comehope 大佬的 前端每日实战 对我的启蒙

已经有了 100+ 的练习, 但这种练习并非刻意针对自己薄弱的问题, 而且对于一些概念还处于 -- "哦, 啊哈, 我懂了(其实并不懂)" 这种自欺欺人的状态

所以也确定了一下我要总结区别于 comehope 大佬总体的练习, 多篇文章会强化某一个属性

box-shadow 第一篇

效果预览

前端 CSS : 2# 纯 CSS 实现多彩的 Buttons(box-shadow)

github.io 浏览

源代码地址

https://github.com/shanyuhai1...

代码解读

首先完成 html 结构

<article>
  <h1>colorful buttons</h1>
  <section class="buttons buttons_inset">
    <h2>inset buttons</h2>
    <button class="button button_top">top</button>
    <button class="button button_right">right</button>
    <button class="button button_bottom">bottom</button>
    <button class="button button_left">left</button>
    <button class="button button_tb">top bottom</button>
    <button class="button button_lr">left right</button>
    <button class="button button_all">all</button>
  </section>
  <section class="buttons buttons_outset">
    <h2>outset buttons</h2>
    <button class="button button_top">top</button>
    <button class="button button_right">right</button>
    <button class="button button_bottom">bottom</button>
    <button class="button button_left">left</button>
    <button class="button button_tb">top bottom</button>
    <button class="button button_lr">left right</button>
    <button class="button button_all">all</button>
  </section>
</article>

完成标题的 样式

body {
  margin: 0;
  height: 100vh;
  font: normal 1em, sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: black;
}

h1,
h2 {
  letter-spacing: 1px;
  text-align: center;
  text-transform: capitalize;
  user-select: none;
}
h1 {
  font-size: 2em;
  color: #066;
  text-shadow: 1px 1px rgba(255, 255, 255, 0.7);
}
h2 {
  background: linear-gradient(45deg, #dbdcd7 0%, #dddcd7 24%, #e2c9cc 30%, #e7627d 46%, #b8235a 59%, #801357 71%, #3d1635 84%, #1c1a27 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

接着将全部按钮 button 设置初始样式

.button {
  font-size: 16px;
  font-weight: 700;
  color: white; /* default */
  text-transform: uppercase;
  background: #d8d8d8;
  border: 2px solid;
  outline: none;
  padding: 1em 2em;
  margin: 0.5em;
  cursor: pointer;
  transition: all .6s, color .3s .4s;
}
.button:hover {
  color: #d8d8d8;
}

添加 box-shadowinset 动画

.button_top {
  color: #5c2223;
  border-image: linear-gradient(to right, #b92b27, #1565c0) 1 1;
  box-shadow: inset 0 2px 1px 0;
}
.button_top:hover {
  box-shadow: inset 0 4em 1px 0 #5c2223;
}

.button_right {
  color: #eba0b3;
  border-image: linear-gradient(to right, #c31432, #240b36) 1 1;
  box-shadow: inset -2px 0 1px 0;
}
.button_right:hover {
  box-shadow: inset -8em 0 1px 0 #eba0b3;
}

.button_bottom {
  color: #c8adc4;
  border-image: linear-gradient(to right, #b92b27, #1565c0) 1 1;
  box-shadow: inset 0 -2px 1px 0;
}
.button_bottom:hover {
  box-shadow: inset 0 -4em 1px 0 #c8adc4;
}

.button_left {
  color: #525288;
  border-image: linear-gradient(to right, #2980b9, #6dd5fa, #ffffff) 1 1;
  box-shadow: inset 2px 0 1px 0;
}
.button_left:hover {
  box-shadow: inset 8em 0 1px 0 #525288;
}

.button_tb {
  color: #131824;
  border-image: linear-gradient(to right, #8e2de2, #4a00e0) 1 1;
  box-shadow: 
    inset 0 2px 1px 0,
    inset 0 -2px 1px 0;
}
.button_tb:hover {
  box-shadow: 
    inset 0 4em 1px 0 #131824,
    inset 0 -4em 1px 0 #131824;
}

.button_lr {
  color: #1e9eb3;
  border-image: linear-gradient(to right, #1f4037, #99f2c8) 1 1;
  box-shadow: 
    inset 2px 0 1px 0,
    inset -2px 0 1px 0;
}
.button_lr:hover {
  box-shadow: 
    inset 8em 0 1px 0 #1e9eb3,
    inset -8em 0 1px 0 #1e9eb3;
}

.button_all {
  color: #45b787;
  border-image: linear-gradient(to right, #a80077, #66ff00) 1 1;
  box-shadow: 
    inset 0 2px 1px 0,
    inset 0 -2px 1px 0,
    inset 2px 0 1px 0,
    inset -2px 0 1px 0;
}
.button_all:hover {
  box-shadow: 
    inset 0 4em 1px 0 #45b787,
    inset 0 -4em 1px 0 #45b787,
    inset 8em 0 1px 0 #45b787,
    inset -8em 0 1px 0 #45b787;
}

再添加 box-shadowoutset 动画

.buttons_outset .button {
  animation: 2s ease-in-out infinite;
}
.buttons_outset .button_top {
  animation-name: shaking-top;
}
.buttons_outset .button_right {
  animation-name: shaking-right;
}
.buttons_outset .button_bottom {
  animation-name: shaking-bottom;
}
.buttons_outset .button_left {
  animation-name: shaking-left;
}
.buttons_outset .button_tb {
  animation-name: shaking-tb;
}
.buttons_outset .button_lr {
  animation-name: shaking-lr;
}
.buttons_outset .button_all {
  animation-name: shaking-all;
}

@keyframes shaking-top {
  50% {
    color: #d8d8d8;
    box-shadow: 0 -2px 1px 0;
    background: #5c2223;
  }
}
@keyframes shaking-right {
  50% {
    color: #d8d8d8;
    box-shadow: 2px 0 1px 0;
    background: #eba0b3;
  }
}
@keyframes shaking-bottom {
  50% {
    color: #d8d8d8;
    box-shadow: 0 2px 1px 0;
    background: #c8adc4;
  }
}
@keyframes shaking-left {
  50% {
    color: #d8d8d8;
    box-shadow: -2px 0 1px 0;
    background: #525288;
  }
}
@keyframes shaking-tb {
  50% {
    color: #d8d8d8;
    box-shadow:
      0 -2px 1px 0,
      0 2px 1px 0;
    background: #131824;
  }
}
@keyframes shaking-lr {
  50% {
    color: #d8d8d8;
    box-shadow:
      -2px 0 1px 0,
      2px 0 1px 0;
    background: #1e9eb3;
  }
}
@keyframes shaking-all {
  50% {
    color: #d8d8d8;
    box-shadow:
      0 -2px 1px 0,
      0 2px 1px 0,
      -2px 0 1px 0,
      2px 0 1px 0;
    background: #45b787;
  }
}

最后

我果然缺乏审美, 自己做的好丑


欢迎大佬补充对 box-shadow 属性的用法

指出我在书写中的不规范及更好的写法

点赞
收藏
评论区
推荐文章
blmius blmius
3年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
皕杰报表之UUID
​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为
Wesley13 Wesley13
3年前
FLV文件格式
1.        FLV文件对齐方式FLV文件以大端对齐方式存放多字节整型。如存放数字无符号16位的数字300(0x012C),那么在FLV文件中存放的顺序是:|0x01|0x2C|。如果是无符号32位数字300(0x0000012C),那么在FLV文件中的存放顺序是:|0x00|0x00|0x00|0x01|0x2C。2.  
Wesley13 Wesley13
3年前
mysql设置时区
mysql设置时区mysql\_query("SETtime\_zone'8:00'")ordie('时区设置失败,请联系管理员!');中国在东8区所以加8方法二:selectcount(user\_id)asdevice,CONVERT\_TZ(FROM\_UNIXTIME(reg\_time),'08:00','0
Wesley13 Wesley13
3年前
PHP创建多级树型结构
<!lang:php<?php$areaarray(array('id'1,'pid'0,'name''中国'),array('id'5,'pid'0,'name''美国'),array('id'2,'pid'1,'name''吉林'),array('id'4,'pid'2,'n
Wesley13 Wesley13
3年前
Java日期时间API系列36
  十二时辰,古代劳动人民把一昼夜划分成十二个时段,每一个时段叫一个时辰。二十四小时和十二时辰对照表:时辰时间24时制子时深夜11:00凌晨01:0023:0001:00丑时上午01:00上午03:0001:0003:00寅时上午03:00上午0
Wesley13 Wesley13
3年前
00:Java简单了解
浅谈Java之概述Java是SUN(StanfordUniversityNetwork),斯坦福大学网络公司)1995年推出的一门高级编程语言。Java是一种面向Internet的编程语言。随着Java技术在web方面的不断成熟,已经成为Web应用程序的首选开发语言。Java是简单易学,完全面向对象,安全可靠,与平台无关的编程语言。
Stella981 Stella981
3年前
Django中Admin中的一些参数配置
设置在列表中显示的字段,id为django模型默认的主键list_display('id','name','sex','profession','email','qq','phone','status','create_time')设置在列表可编辑字段list_editable
Wesley13 Wesley13
3年前
MySQL部分从库上面因为大量的临时表tmp_table造成慢查询
背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_
Python进阶者 Python进阶者
1年前
Excel中这日期老是出来00:00:00,怎么用Pandas把这个去除
大家好,我是皮皮。一、前言前几天在Python白银交流群【上海新年人】问了一个Pandas数据筛选的问题。问题如下:这日期老是出来00:00:00,怎么把这个去除。二、实现过程后来【论草莓如何成为冻干莓】给了一个思路和代码如下:pd.toexcel之前把这
美凌格栋栋酱 美凌格栋栋酱
5个月前
Oracle 分组与拼接字符串同时使用
SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(