我正在尝试创建这样的按钮:
[在线研究后,我只想出了一个平行四边形。但这是结果:
代码:
.parallelogram {
width: 100px;
height: 50px;
transform: skew(25deg);
background: black;
border: 1px solid #EC00F4;
color: white;
box-shadow: 0px 3px 8px #EC00F4;
}
<button class="parallelogram"> Hello button </button>
是否有一种方法可以使边缘移到我想要的位置(如图中所示,但不移动文本?
在伪元素上使用两个剪切路径:
.parallelogram {
padding:20px 50px;
font-size:30px;
color: white;
border:none;
background:none;
outline:none;
position:relative;
z-index:0;
margin:20px;
filter:drop-shadow(0px 30px 25px rgba(236, 0, 244, 0.45));
}
.parallelogram:before,
.parallelogram:after {
content:"";
position:absolute;
z-index:-1;
top:0;
left:0;
right:0;
bottom:0;
clip-path: polygon(0 11%, 100% 0, 90% 88%, 3% 96%);
transition:1s all;
background:#000;
}
.parallelogram:before {
background:#EC00F4;
transform:scale(1.05,1.12);
}
.parallelogram:hover:before,
.parallelogram:hover:after {
clip-path: polygon(5% 2%, 100% 5%, 100% 100%, 0% 94%);
}
<button class="parallelogram"> Hello button </button>
<button class="parallelogram"> button </button>
您可以使用伪元素设置透视效果:
示例
.parallelogram {
width: 100px;
height: 50px;
position: relative;
color: white;
/* appearance:none; could be used too */
background: none;
border: none;
cursor: pointer; /* show where and that i'm clickable */
}
.parallelogram:before {
content: "";
position: absolute;
z-index: -1;
top: 0;
left: 0;
width: 110%; /* might need to be resized */
height: 100%;
transform: /* tune the rotation and perspective values to your needs */
perspective(200px)
rotatey(35deg)
rotatex(-25deg)
;
background: black;
border: 2px solid #ec00f4;
box-shadow: 0px 3px 8px #ec00f4;
}
<button class="parallelogram"> Hello button </button>
这有点像您想要的:
button{
width: 150px;
height: 50px;
-webkit-clip-path: polygon(0% 20%, 92% 14%, 88% 88%, 0% 100%);
clip-path: polygon(0% 20%, 92% 14%, 88% 88%, 0% 100%);
background: black;
color: white;
}
<button class="parallelogram"> Hello button </button>
编辑:
您可以在此处创建与按钮完全一样的SVG:https://vectr.com/new
您可以添加边框+阴影,只需复制html。
使用类.unskew添加跨度,并在背景上执行与倾斜效果相反的操作,并更改显示规则。
示例:
CSS
.parallelogram {
transition: background 0.3s;
transform: skew(-25deg);
/* SKEW */
}
.unskew{
display: block;
/* block or inline-block is needed */
text-decoration: none;
padding: 5px 10px;
font: 30px/1 sans-serif;
transform: skew(25deg);
/* UNSKEW */
color: inherit;
}
HTML
<button class="parallelogram"><span class="unskew" >Hello button</span></button>