将多个形状放在正确位置的更好方法
Better way to put several shapes in the right places
我正在尝试使用 CSS 制作一个 crystal 栏。
Here is a JS Bin
根据显示器的分辨率不同,这3个形状会错位。我遇到过很多次把形状放在正确的地方。有没有更好的方法来操纵形状的位置?
编辑:
我的第二种方法 (another JS Bin) 制作 div 将形状组合在一起。但这也不好用。 (不能居中形状也不能旋转)
这就是你的想法?
<div class="bar"></div>
body {
background: #111;
}
.bar {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
width: 10px;
height: 200px;
background-color: #aef;
-webkit-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
}
.bar:before, .bar:after {
position: absolute;
left: 0;
width: 0;
height: 0;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
content: '';
}
.bar:before {
top: -10px;
border-bottom: 10px solid #aef;
}
.bar:after {
bottom: -10px;
border-top: 10px solid #aef;
}
我正在尝试使用 CSS 制作一个 crystal 栏。
根据显示器的分辨率不同,这3个形状会错位。我遇到过很多次把形状放在正确的地方。有没有更好的方法来操纵形状的位置?
编辑: 我的第二种方法 (another JS Bin) 制作 div 将形状组合在一起。但这也不好用。 (不能居中形状也不能旋转)
这就是你的想法?
<div class="bar"></div>
body {
background: #111;
}
.bar {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
width: 10px;
height: 200px;
background-color: #aef;
-webkit-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
}
.bar:before, .bar:after {
position: absolute;
left: 0;
width: 0;
height: 0;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
content: '';
}
.bar:before {
top: -10px;
border-bottom: 10px solid #aef;
}
.bar:after {
bottom: -10px;
border-top: 10px solid #aef;
}