我需要帮助使用剪辑路径 css 在形状(陡峭的平行四边形)上制作 2px 边框
I need help making a 2px border on a shape ( a steep angled parallelogram) using clip path css
我将最喜欢的技术应用于不同的形状,但我无法让右侧边框看起来与我想要的 2px 边框成比例。
Link to example
.tabular_one{
display: inline-block;
position: relative;
width: 500px;
height: 30px;
background: black;
box-sizing: border-box;
-webkit-clip-path: polygon(0 0, 100% 0, 90% 100%, 0 100%);
clip-path: polygon(0 0, 100% 0, 90% 100%, 0 100%);
}
.tabular_one h2{
margin: 0;
position: absolute;
top: 2px;
left: 2px;
width: 496px;
height: 26px;
background-color: #277455;
-webkit-clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%);
clip-path: polygon(0 0, 100% 0, 90% 100%, 0 100%);
}
<div>
<div class="tabular_one">
<h2>TAKE A LOOK AT WHAT WE DO!</h2>
</div>
</div>
Link 在 codepen 中编码:Example in Code pen
- 另外,这个方法是业界首选还是绘制一个SVG图像并设置为背景更好?
您可以使用 px
而不是 %
将内部形状从外部形状偏移 2px,如下所示:
.box{
display: block;
position: relative;
width: 500px;
height: 30px;
background: black;
clip-path: polygon(0 0, 100% 0, 90% 100%, 0 100%);
}
.box h2{
padding:0;
margin: 0;
display: block;
position: absolute;
width: 500px;
height: 30px;
background-color: red;
clip-path: polygon(2px 2px, 493px 2px, 449px 28px, 2px 28px);
}
这是另一个想法skew
转换和伪元素。您还将获得比 clip-path
:
更好的支持
h2 {
display: inline-block;
position: relative;
height: 30px;
background: #277455;
border: 2px solid #000;
border-right: none;
box-sizing: border-box;
z-index: 0;
}
h2:before {
content: "";
position: absolute;
z-index: -1;
top: -2px;
bottom: -2px;
left: 100%;
width: 30px;
border: 2px solid #000;
border-left: navajowhite;
background-color: #277455;
transform-origin: top right;
transform: skew(-45deg);
}
<h2>TAKE A LOOK AT WHAT WE DO!</h2>
我将最喜欢的技术应用于不同的形状,但我无法让右侧边框看起来与我想要的 2px 边框成比例。
Link to example
.tabular_one{
display: inline-block;
position: relative;
width: 500px;
height: 30px;
background: black;
box-sizing: border-box;
-webkit-clip-path: polygon(0 0, 100% 0, 90% 100%, 0 100%);
clip-path: polygon(0 0, 100% 0, 90% 100%, 0 100%);
}
.tabular_one h2{
margin: 0;
position: absolute;
top: 2px;
left: 2px;
width: 496px;
height: 26px;
background-color: #277455;
-webkit-clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%);
clip-path: polygon(0 0, 100% 0, 90% 100%, 0 100%);
}
<div>
<div class="tabular_one">
<h2>TAKE A LOOK AT WHAT WE DO!</h2>
</div>
</div>
Link 在 codepen 中编码:Example in Code pen
- 另外,这个方法是业界首选还是绘制一个SVG图像并设置为背景更好?
您可以使用 px
而不是 %
将内部形状从外部形状偏移 2px,如下所示:
.box{
display: block;
position: relative;
width: 500px;
height: 30px;
background: black;
clip-path: polygon(0 0, 100% 0, 90% 100%, 0 100%);
}
.box h2{
padding:0;
margin: 0;
display: block;
position: absolute;
width: 500px;
height: 30px;
background-color: red;
clip-path: polygon(2px 2px, 493px 2px, 449px 28px, 2px 28px);
}
这是另一个想法skew
转换和伪元素。您还将获得比 clip-path
:
h2 {
display: inline-block;
position: relative;
height: 30px;
background: #277455;
border: 2px solid #000;
border-right: none;
box-sizing: border-box;
z-index: 0;
}
h2:before {
content: "";
position: absolute;
z-index: -1;
top: -2px;
bottom: -2px;
left: 100%;
width: 30px;
border: 2px solid #000;
border-left: navajowhite;
background-color: #277455;
transform-origin: top right;
transform: skew(-45deg);
}
<h2>TAKE A LOOK AT WHAT WE DO!</h2>