CSS 具有不规则矩形和边框的自定义形状
CSS custom shape with irregular rectangle and border
我正在尝试创建这样的按钮:
网上查了下,才想出做一个平行四边形。但这是结果:
代码:
.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>
有没有办法让边缘移动到我想要的位置(如图所示)但不移动文本?
这有点像你想要的那样:
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。
添加跨度,使用 class .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>
您可以使用伪元素来设置您的透视效果:
例子
.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>
来自火狐的截图:
在伪元素上使用 clip-path。诀窍是考虑相同的剪辑路径并对一个伪元素应用缩放变换以模拟边框。只需调整多边形的值即可获得所需的结果。
悬停鼠标以查看不同的剪辑路径:
.parallelogram {
padding:20px 45px;
font-size:30px;
color: white;
border:none;
background:none;
outline:none;
position:relative;
z-index:0;
margin:15px;
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>
<button class="parallelogram"> A </button>
你也可以考虑像素值来保持相同的形状,不管里面的内容是什么:
.parallelogram {
padding:20px 45px;
font-size:30px;
color: white;
border:none;
background:none;
outline:none;
position:relative;
z-index:0;
margin:15px;
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 10px, 100% 0, calc(100% - 8px) calc(100% - 15px), 5px calc(100% - 8px));
transition:1s all;
background:#000;
}
.parallelogram:before {
background:#EC00F4;
transform:scale(1.05,1.12);
}
.parallelogram:hover:before,
.parallelogram:hover:after {
clip-path: polygon(0 5px, 100% 0, 100% 100%, 10px calc(100% - 20px));
}
<button class="parallelogram"> Hello button </button>
<button class="parallelogram"> button </button>
<button class="parallelogram"> A </button>
我正在尝试创建这样的按钮:
网上查了下,才想出做一个平行四边形。但这是结果:
代码:
.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>
有没有办法让边缘移动到我想要的位置(如图所示)但不移动文本?
这有点像你想要的那样:
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。
添加跨度,使用 class .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>
您可以使用伪元素来设置您的透视效果:
例子
.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>
来自火狐的截图:
在伪元素上使用 clip-path。诀窍是考虑相同的剪辑路径并对一个伪元素应用缩放变换以模拟边框。只需调整多边形的值即可获得所需的结果。
悬停鼠标以查看不同的剪辑路径:
.parallelogram {
padding:20px 45px;
font-size:30px;
color: white;
border:none;
background:none;
outline:none;
position:relative;
z-index:0;
margin:15px;
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>
<button class="parallelogram"> A </button>
你也可以考虑像素值来保持相同的形状,不管里面的内容是什么:
.parallelogram {
padding:20px 45px;
font-size:30px;
color: white;
border:none;
background:none;
outline:none;
position:relative;
z-index:0;
margin:15px;
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 10px, 100% 0, calc(100% - 8px) calc(100% - 15px), 5px calc(100% - 8px));
transition:1s all;
background:#000;
}
.parallelogram:before {
background:#EC00F4;
transform:scale(1.05,1.12);
}
.parallelogram:hover:before,
.parallelogram:hover:after {
clip-path: polygon(0 5px, 100% 0, 100% 100%, 10px calc(100% - 20px));
}
<button class="parallelogram"> Hello button </button>
<button class="parallelogram"> button </button>
<button class="parallelogram"> A </button>