【发布时间】:2018-10-02 15:34:15
【问题描述】:
我想实现以下目标:
如您所见,有四个矩形的边都应用了倾斜,因此最终可以将四个矩形连接起来形成一个正方形。
我想让它动态化,所以一根管道可以有一个、两个或不倾斜的侧面。
这是我对这个问题的看法:
<div>
<div class="v vr">
<div class="pipe">
</div>
</div>
<div class="v vl">
<div class="pipe">
</div>
</div>
<div class="h ht hle hre">
<div class="pipe">
</div>
</div>
<div class="h hb">
<div class="pipe">
</div>
</div>
</div>
这里是 CSS:
.pipe {
position: relative;
width: 100%;
border: none;
display: inline-block;
height: 100%;
padding: 0px;
margin: 0 1px;
background: linear-gradient(#737373 30%, #cccccc 50%, #737373 70%);
}
.v .pipe {
background: linear-gradient(to right, #737373 30%, #cccccc 50%, #737373 70%)
}
.vr{
min-width: 15px;
min-height: 250px;
position: absolute;
z-index: 10014;
top: 380px;
left: 840px;
width: 15px;
height: 250px;
}
.ht{
min-width: 250px;
min-height: 15px;
position: absolute;
z-index: 10017;
top: 355px;
left: 585px;
width: 250px;
height: 15px;
transform: rotate(90);
}
.hb{
min-width: 250px;
min-height: 15px;
position: absolute;
z-index: 10017;
top: 630px;
left: 585px;
width: 250px;
height: 15px;
transform: rotate(90);
}
.vl{
min-width: 15px;
min-height: 250px;
position: absolute;
z-index: 10014;
top: 380px;
left: 560px;
width: 15px;
height: 250px;
}
.ht.hle .pipe:first-child:after {
content: " ";
position: absolute;
display: block;
width: 100%;
height: 100%;
top: 0;
left: 0;
z-index: 999999999;
background: linear-gradient(#737373 30%, #cccccc 50%, #737373 70%);
transform-origin: bottom left;
-ms-transform: skew(50deg,0deg);
-webkit-transform: skew(50deg,0deg);
transform: skew(50deg);
}
.ht.hre .pipe:nth-child(1):before {
content: " ";
position: absolute;
display: block;
width: 100%;
height: 100%;
top: 0;
left: 0;
z-index: 999999999;
background: linear-gradient(#737373 30%, #cccccc 50%, #737373 70%);
transform-origin: left bottom;
-ms-transform: skew(28deg,0deg);
-webkit-transform: skew(28deg,0deg);
transform: skew(-50deg);
//background: white;
}
【问题讨论】:
-
所以不是编码机器,请向我们展示您的代码
-
好好想想,也许你想要别的东西?
-
@לבנימלכה 这里是:codepen.io/HMubaireek/pen/odjWJE
-
@TemaniAfif 我想到了 SVG,我认为 CSS 会更容易。