简体   繁体   English

如何叠加内嵌的CSS形状?

[英]How do I overlay CSS shapes positioned inline?

I have been trying to create a Hexagonal border with pure CSS with a check mark in it. 我一直在尝试使用带有复选标记的纯CSS创建一个六边形边框。

I found Hexagon shape with a border/outline and the answer by JoshC worth pursuing. 我发现六角形的边框/轮廓JoshC的答案值得追求。 I created a fiddle an have been trying to get the shapes to behave inline. 我创造了一个小提琴 ,一直试图让形状表现为内联。 It is my intention to convert this to use em vs px after completion. 我打算在完成后将其转换为使用em vs px。

I can get two of the three to position correctly but not the third. 我可以让三个中的两个正确定位而不是第三个。 I have not tried to get my check in the box yet. 我还没有尝试过我的支票。 I have taken JoshC's CSS and created a base class to minimize duplicate settings. 我已经使用了JoshC的CSS并创建了一个基类来最小化重复设置。 And have made progress but I have not succeeded. 并取得了进展,但我没有成功。 The basic premise is here, withe the fiddle being more involved. 基本前提是在这里,小提琴更多涉及。 There is also a matter of white space below the shape. 形状下方还有白色空间。

在此输入图像描述

✔
<div class="hex hex1"></div>
<div class="hex hex2"></div>
<div class="hex hex3"></div>

Body{font-size:24px;}
.hex:before{content:"";width:0;height:0;border-bottom:30px solid #6C6;border-left:52px solid transparent;border-right:52px solid transparent;position:absolute;top:-30px;left:0;}
.hex{margin-top:30px;margin-bottom:30px;width:104px;height:60px;background-color:#6C6;position:relative;}
.hex:after{content:"";width:0;position:absolute;bottom:-30px;border-top:30px solid #6C6;border-left:52px solid transparent;border-right:52px solid transparent;left:0;}

.hex1:before{border-bottom:30px solid #6C6;border-left:52px solid transparent;border-right:52px solid transparent;}
.hex1{background-color:#6C6;position:relative;}
.hex1:after{border-top:30px solid #6C6;border-left:52px solid transparent;border-right:52px solid transparent;left:0;}

.hex2:before{border-bottom:30px solid red;border-left:52px solid transparent;border-right:52px solid transparent;}
.hex2{background-color:red;position:relative;top:0;-webkit-transform:scale(.6);-moz-transform:scale(.6);transform:scale(.6);z-index:3;}
.hex2:after{border-top:30px solid red;border-left:52px solid transparent;border-right:52px solid transparent;left:0;}

.hex3:before{border-bottom:30px solid blue;border-left:52px solid transparent;border-right:52px solid transparent;}
.hex3{background-color:blue;position:relative;top:-90px;-webkit-transform:scale(.8,.8);-moz-transform:scale(.8,.8);transform:scale(.8,.8);}
.hex3:after{border-top:30px solid blue;border-left:52px solid transparent;border-right:52px solid transparent;left:0;}

Updated my fiddle based on the answer by GCyrillus ! 根据GCyrillus的答案更新了我的小提琴 I added -webkit-transform:scale for chrome. 我添加了-webkit-transform:scale for chrome。

what about : 关于什么 :

<div class="hex hex1">
    <div class="hex hex2">
        <div class="hex hex3">
              ✔
        </div>
    </div>
</div>

http://codepen.io/gc-nomade/pen/xEFaB http://codepen.io/gc-nomade/pen/xEFaB

nest your element and use less relative/top : -xx ; 嵌套你的元素并使用较少的relative / top:-xx; it will stand in the flow much more easier 它将更容易站在流程中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM