Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I overlay CSS shapes positioned inline?

Tags:

html

css

I have been trying to create a Hexagonal border with pure CSS with a check mark in it.

I found Hexagon shape with a border/outline and the answer by JoshC worth pursuing. 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.

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. 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.

enter image description here

✔
<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! I added -webkit-transform:scale for chrome.

like image 658
Joe Johnston Avatar asked Jul 04 '26 16:07

Joe Johnston


1 Answers

what about :

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

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

nest your element and use less relative/top : -xx ; it will stand in the flow much more easier

like image 186
G-Cyrillus Avatar answered Jul 07 '26 05:07

G-Cyrillus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!