htmlcss
<nav>click me</nav>
csshtml
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); }
效果图spa
若是咱们想获得向左侧倾斜或者向右侧倾斜的梯形,只须要将transform-origin设置为bottom left 或者 bottom right便可3d
csscode
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; }
效果图orm