css实现梯形标签页

html

<nav>click me</nav>

css

nav{
  position: relative;
  display: inline-block;
  padding: 15px;
  font-size: 24px;
  color: white;
  margin: 50px;
}
nav::before{
  content: '';
  position: absolute;
  top:0;left:0;right:0;bottom:0;
  z-index: -1;
  background: #58a;
  transform: perspective(.5em) rotateX(5deg);
}

效果图

如果我们想得到向左侧倾斜或者向右侧倾斜的梯形,只需要将transform-origin设置为bottom left 或者 bottom right即可

css

nav{
  position: relative;
  display: inline-block;
  padding: 50px 40px 15px 15px;
  font-size: 24px;
  color: white;
  margin: 50px;
}
nav::before{
  content: '';
  position: absolute;
  top:0;left:0;right:0;bottom:0;
  z-index: -1;
  background: #58a;
  transform: perspective(.5em) rotateX(5deg);
  transform-origin: bottom left;
}

效果图

 

posted @ 2017-11-21 18:22  孟丽媛  Views(5486)  Comments(0Edit  收藏  举报