html - Using CSS to create hidden background divs -
i followed excellent post on creating grid of responsive squares create, well, grid of responsive squares.
what need create 2 background divs span half height , full width can attach events them. these divs however, cannot interfere content in cell.
this square looks in html
:
<div class="row-content"> <div class="content"> <div class="table"> <div class="table-cell numbers"> <span>100.08</span> </div> </div> </div> </div>
and css
.row-content { float:left; position: relative; width: 8%; /* 1 divide number of columns */ padding-bottom : 8%; /* = width 1:1 aspect ratio */ margin:0.16667%; /* = (100% - (% width * columns)) / (columns * 2) */ background-color:#1e1e1e; overflow:hidden; } .content { position:absolute; height:98%; /* = 100% - 2*10% padding */ width:98%; /* = 100% - 2*5% padding */ padding: 1%; } .table{ display:table; width:100%; height:100%; } .table-cell{ display:table-cell; vertical-align:middle; } .numbers{ font-weight:900; font-size:12px; color:#fff; }
this results in following:
here's fiddle.
i'd 2 "hidden" divs behind content. hidden mean divs no content, there solely purpose of attaching events. this:
i'm using bootstrap 3 , jquery.
add position: relative;
.numbers
class in css.
create 2 divs, , add them absolute.
if want show divs behind content add this, added. or remove if want close content divs.
/* shows content above divs */ .numbers > span { position: relative; z-index: 1; }
here code:
#d1, #d2 { width: 100%; height: 50%; left: 0; position: absolute; } #d1 { top: 0; background-color: rgba(51,107,230,.5); } #d2 { bottom: 0; background-color: rgba(255,221,0,.5); } /* shows content above divs */ .numbers > span { position: relative; z-index: 1; } .row-content { float:left; position: relative; width: 8%; /* 1 divide number of columns */ padding-bottom : 8%; /* = width 1:1 aspect ratio */ margin:0.16667%; /* = (100% - (% width * columns)) / (columns * 2) */ background-color:#1e1e1e; overflow:hidden; } .content { position:absolute; height:98%; /* = 100% - 2*10% padding */ width:98%; /* = 100% - 2*5% padding */ padding: 1%; } .table{ display:table; width:100%; height:100%; } .table-cell{ display:table-cell; vertical-align:middle; } .numbers{ font-weight:900; font-size:16px; color:#fff; position: relative; }
<div class="row-content"> <div class="content"> <div class="table"> <div class="table-cell numbers"> <span>100.08</span> <div id="d1"></div> <div id="d2"></div> </div> </div> </div> </div>
Comments
Post a Comment