【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);
}
相关推荐
金八梭1 小时前
格斗对决v4.5
前端·css·自动化·html·css3
CappuccinoRose2 天前
前端开发交互体系 - 汇总篇
开发语言·前端·javascript·css·html·交互
inksci4 天前
用飞帆做了个小网页
前端·javascript·css·html
星云_byto4 天前
CSS面试题
前端·css
科研邪修法4 天前
PDF新增页面文字与文本批注怎么区分?以双版本培训讲义为例
前端·css·pdf
狮子座的男孩5 天前
html+css基础:31、响应式布局(媒体类型,媒体特性,运算符,常用阈值)
前端·css·经验分享·html·响应式布局·媒体类型/特性·常用阈值
狮子座的男孩5 天前
html+css基础:32、BFC(父子元素防止 margin 塌陷,父子元素清除浮动,兄弟元素两栏布局)
前端·css·经验分享·html·bfc·margin塌陷·清除浮动
吴长建先生6 天前
Flutter IM 即时聊天应用开发:从 0 到 1 实
css
htzyl2067 天前
前端样式-弹窗淡入淡出,为什么你的 `transition` 一直不生效
前端·css·html
Brookty7 天前
CSS基础知识(二):盒模型、内外边距、外边距折叠与父子元素的布局关系
前端·css