css - Overlapping elements within a square grid -
i’ve implement layout based on square grid. shown on following image, elements have overlap responsive within grid. (the squares offset on x-axis , overlap 1 grid cell on y-axis.)
http://i.stack.imgur.com/9bz5g.jpg
does know how achieve effect? i'm using framework foundation 6. i’d prefer solution without javascript. can’t use foundation .#-push-# , .#pull-# classes because shift elements inwards , 2 squares have in separate rows.
i’ve set jsfiddle containing 2 squares.
.square { background: #f00; position: relative; } .square:after { content: ""; display: block; padding-bottom: 100%; } .content { position: absolute; width: 100%; height: 100%; } .dark { background: #cbcbcb; } .light { background: #dedede; }
<link href="https://cdnjs.cloudflare.com/ajax/libs/foundation/6.2.0/foundation.css" rel="stylesheet"/> <div class="row"> <div class="small-12 columns"> <div class="row"> <div class="small-8 columns end"> <div class="square dark"> <div class="content">test</div> </div> </div> </div> <div class="row"> <div class="small-6 small-offset-6 columns end"> <div class="square light"> <div class="content">test</div> </div> </div> </div> </div> </div>
many in advance help.
it seems work if calculate offset percent , mind column spacing. therefore adjustet snippet , added square 4 colums:
.square { background: #f00; position: relative; } .square:after { content: ""; display: block; padding-bottom: 100%; } .content { position: absolute; width: 100%; height: 100%; } .dark { background: #cbcbcb; } .light { background: #dedede; } /* new */ .small-6.columns.overlap-top > .square { margin-top: calc(-33.3% + 1.33*0.625rem); // 1 third 33.3% minus 1.33 times col spacing } .small-4.columns.overlap-top > .square { margin-top: calc(-50% + 1*0.625rem); // 1 half 50% minus 1 times col spacing } @media screen , (min-width: 40em) { .small-6.columns.overlap-top > .square { margin-top: calc(-33.3% + 1.33*0.9375rem); } .small-4.columns.overlap-top > .square { margin-top: calc(-50% + 1*0.9375rem); } }
<link href="https://cdnjs.cloudflare.com/ajax/libs/foundation/6.2.0/foundation.css" rel="stylesheet"/> <div class="row"> <div class="small-12 columns"> <div class="row"> <div class="small-8 columns end"> <div class="square dark"> <div class="content">square 1</div> </div> </div> </div> <div class="row"> <!-- new class overlap-top --> <div class="small-6 small-offset-6 columns overlap-top end"> <div class="square light"> <div class="content">square 2</div> </div> </div> </div> <!-- new square --> <div class="row"> <div class="small-4 small-offset-4 columns overlap-top end"> <div class="square dark"> <div class="content">square 3</div> </div> </div> </div> </div> </div>
jsfiddle: https://jsfiddle.net/jwt0k1pw/1/
hope helps!
Comments
Post a Comment