【CSS】倾斜按钮

效果

index.html

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> Document </title>
    <link type="text/css" rel="styleSheet" href="index.css" />
  </head>
  <body>
    <div class="container">
      <button type="button"><span>倾斜按钮</span> </button>
    </div>
  </body>
</html>

index.css

css 复制代码
  /*设置button元素样式*/
button {
  width: 180px;
  height: 80px;
  /*设置button元素 背景颜色*/
  background: #000;
  /*设置button元素 无边框*/
  border: none;
  /*设置button元素 无轮廓线*/
  outline: none;
  /*设置button元素 将显示为块级元素*/
  display:  block;
  margin: 0 auto;
  /*设置button元素 字体颜色*/
  color:  #fff;
  /*设置button元素 字体大小*/
  font-size:  18px;
  /*设置button元素 圆角左上和右下的圆角15px*/
  border-radius: 15px 0;
  /*设置button元素 相对位置*/
  position: relative;
  /*设置button元素 倾斜-20°*/
  transform: skew(-20deg);
}
/*设置伪元素::before 的样式*/
button::before {
  content: '';
  /*绝对位置*/
  position: absolute;
  /*伪元素的宽度*/
  width: 20px;
  /*伪元素的高度*/
  height: 20px;
  /*伪元素的背景颜色为径向渐变背景*/
  /*circle at 0 0 设置圆心位置-左上角*/
  /*transparent 0 20px 从圆心开始到半径为 20px 的位置,逐渐变为透明*/
  /*transparent 0 20px 从圆心开始到半径为 5px 的位置,逐渐变为黑色,超过5px都为黑色*/
  background: radial-gradient(
    circle at 0 0,
    transparent 0 20px, 
    #000 5px
  );
  /*伪元素从父元素的底部开始绘制*/
  bottom: 0px;
  /*伪元素从父元素的左端-20px开始绘制*/
  left: -20px;
}

/*设置伪元素::after 的样式*/
button::after {
  content: '';
  /*绝对位置*/
  position: absolute;
  /*伪元素的宽度*/
  width: 20px;
  /*伪元素的高度*/
  height: 20px;
  /*伪元素的背景颜色为径向渐变背景*/
  /*circle at 100% 100% 设置圆心位置-右下角*/
  /*transparent 0 20px 从圆心开始到半径为 20px 的位置,逐渐变为透明*/
  /*transparent 0 20px 从圆心开始到半径为 5px 的位置,逐渐变为黑色,超过5px都为黑色*/
  background: radial-gradient(
    circle at 100% 100%,
    transparent 0 20px,
    #000 5px
  );
  /*伪元素从父元素的顶部开始绘制*/
  top: 0px;
  /*伪元素从父元素的右端-20px开始绘制*/
  right: -20px;
}

button span{
  /*设置button span元素 将显示为块级元素*/
  display: block;
  /*抵消按钮的倾斜,让文字回正*/
  transform: skew(20deg);
}
相关推荐
finyouIT3 分钟前
锚点实现了点击导航平滑滚动到页面指定位置的三种方法
javascript·css
用户059540174463 小时前
用了半年 LangChain Memory,才发现记忆总“串台”——3 个自动化测试避坑指南
前端·css
More more4 小时前
纯手搓css样式:科技感弹窗边框
css·科技·css3
kidding72321 小时前
旋转大转盘小程序
前端·css·微信小程序·小程序·前端框架
用户059540174461 天前
AI 客服突然“失忆”,排查 6 小时发现 LangChain 记忆存储的 3 个致命坑
前端·css
晓得迷路了1 天前
栗子前端技术周刊第 136 期 - pnpr、Flow 重构移植 Rust、Astryx...
前端·javascript·css
丨我是张先生丨1 天前
英语单词 Web Page
前端·css·css3
疯狂的魔鬼2 天前
精确计算容器剩余视口高度:useAutoContainerFullHeight 的工程实践
前端·css·typescript
用户059540174462 天前
用了 3 个月 ChatGPT,才发现它一直在遗忘——用 Playwright 自动化验证记忆存储一致性
前端·css
spmcor2 天前
CSS 黏性定位完全指南:从入门到精通
css