转载自:https://www.cnblogs.com/sharpall/p/6113377.html
<html>
<head>
<style type="text/css">
.location{
}
.button{
display:inline-block;
position: relative;
top: 150px;
left: 150px;
color: white;
background-color: #51bfff;
width: 120px;
height: 50px;
line-height: 50px;
text-align: center;
transform: skewX(-45deg); //改变;倾斜角度
}
</style>
</head>
<body>
<span class="location button">click</span>
</body>
</html>
<style>
.location{
position: relative;
top: 150px;
left: 150px;
}
.button{
width: 120px;
height: 50px;
line-height: 50px;
text-align: center;
color: white;
}
.button:before{
content: '';
position: absolute;
top: 0; right: 0; bottom: 0; left: 0;
background-color: #51bfff;
transform: skewX(-45deg);
z-index: -1;
}
</style>
</head>
<body>
<div class="location button">click</div>
这样不但解决了内容倾斜的问题,而且html结构还是和之前一样干净。不过要注意伪元素生成的图案是重叠在内容之上的,一旦给它设置背景,就会遮住内容,所以要加上z-index: -1。