html - Responsive layout & column float issue -
i'm trying achieve layout series of tiled divs in single row using bootstrap 3.2.0, screens > 768px
wide. div heights either single or double, in sample i've set 50px
, 100px
, div widths controlled class col-sm-x
:
my best attempt far uses below markup & css:
css
.red{ background-color: red; } .blue{ background-color: blue; } .green{ background-color: green; } .yellow{ background-color: yellow; } .purple{ background-color: purple; } .home-height-single{ min-height: 50px; } .home-height-double{ min-height: 100px; } @media (min-width: 768px) { .b-col { float: right; } }
markup:
<div class="row"> <div class="col-sm-6 home-height-double green"> <p>1</p> </div> <div class="col-sm-4 home-height-single blue b-col"> <p>3</p> </div> <div class="col-sm-2 home-height-single purple b-col"> <p>2</p> </div> <div class="col-sm-2 home-height-single green b-col"> <p>7</p> </div> <div class="col-sm-4 home-height-double yellow b-col"> <p>6</p> </div> <div class="col-sm-2 home-height-single blue"> <p>4</p> </div> <div class="col-sm-4 home-height-single red"> <p>5</p> </div> <div class="col-sm-2 home-height-single red b-col"> <p>8</p> </div> </div>
this produces below, div 8 isn't filling gap:
jsfiddle - showing issue
i'm aware create 2 columns , wrap divs in 2 parent divs, want avoid this. reason being on mobile view, want place divs 2 & 4 side side, rather have them stacked, don't believe can if divs wrapped in 2 columns.
for example, i'm planning setup mobile view once i've got past issue:
do jquery
$(function(){ var el = $(".row div:last-child"); el.css('top', el.height() * -1); $( window ).resize(function() { if($( window ).width() < 768){ el.css('top', 0); }else{ el.css('top', el.height() * -1); }; }); })
and let me know if find css-only solution.
Comments
Post a Comment