我有一排使用CSS的六边形,但是我需要在一排中有7个六边形,由于某种原因,它们已被切除(中间的六边形除外),如下所示:
这是我到目前为止的代码:
.hex-container {
width:310px;
text-align:center;
position:relative;
}
.hex-container div{
display:inline-block;
width:120px;
height:104px;
margin:0 -13px;
clip-path: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%);
}
.hex-container div::before {
content:"";
position:absolute;
top:0;
left:0;
right:0;
bottom:0;
background:linear-gradient(45deg, #f09800,#fad900);
}
.hex-container div:nth-child(1),
.hex-container div:nth-child(3),
.hex-container div:nth-child(4),
.hex-container div:nth-child(6) {
margin-top:54px;
margin-bottom:-54px;
}
<div class="hex-container">
<div></div>
<div></div>
<div></div>
</div>
去除负边距底部并使用 vertical-align:top
.hex-container {
width:310px;
text-align:center;
position:relative;
}
.hex-container div{
display:inline-block;
vertical-align:top; /* here */
width:120px;
height:104px;
margin:0 -13px;
clip-path: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%);
}
.hex-container div::before {
content:"";
position:absolute;
top:0;
left:0;
right:0;
bottom:0;
background:linear-gradient(45deg, #f09800,#fad900);
}
.hex-container div:nth-child(odd){
margin-top:54px;
}
<div class="hex-container">
<div></div><div></div><div></div>
</div>
以及具有7种形状的完整代码:
.hex-container {
text-align:center;
width:700px;
position:relative;
}
.hex-container div{
display:inline-block;
vertical-align:top; /* here */
width:120px;
height:104px;
margin:0 -13px;
clip-path: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%);
}
.hex-container div::before {
content:"";
position:absolute;
top:0;
left:0;
right:0;
bottom:0;
background:linear-gradient(45deg, #f09800,#fad900);
}
.hex-container div:nth-child(odd){
margin-top:54px;
}
<div class="hex-container">
<div></div><div></div><div></div><div></div><div></div><div></div><div></div>
</div>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句