css - Going from 2 to 3 columns when expanding the width of screen -
when screen expands past width i'd add column unordered list items, 2 columns 3 columns. i'm not sure how this? bootstrap seems has solution i've never used it. here jsfiddle: http://jsfiddle.net/en9qm/
the html
<div class="sidebar"> <div class="search-filters">filters</div> <div class="search-results"> <div class="listings"> <ul> <li>hello</li> <li>byebye</li> <li>chuck</li> <li>paul</li> </ul> </div> <div class="listings-footer"></div> </div> </div>
the css
.sidebar { position: fixed; top: 47px; right: 0; bottom: 0; width: 60 % ; overflow - y: scroll; /*-webkit-overflow-scrolling: touch; background: #f7f7f7;*/ background - color: aqua; /*border: 3px solid black;*/ } .search - filters { background - color: white; height: 40 % ; } .search - results { padding: 10px 0 20px 20px; border: 3px solid black; height: 100 % ; } .listings { border: 3px solid red; height: 100 % ; } .listings - footer { border: 3px solid blue; /*height: 92px; height: 100%;*/ } ul { /*width:100%;*/ list - style - type: none; /*height: 100%;*/ background - color: pink; } li { background: green; float: left; height: 250px; margin: 0 10px 10px 0; width: 45 % ; }@ media(min - width: 1200px) { li { width: 25 % ; } } li: nth - child(even) { margin - right: 0; }
you on right track media query. have change width
inside it.
@media (min-width: 1200px) { li, li:nth-child(even) { width:30%; margin-right: 3.33%; } }
(see jsfiddle) means when screen @ least 1200px wide, columns occupy 30% of container, plus 3.33% of right margin. overrode li:nth-child(even)
second column have right margin well.
bootstrap uses grid system of 12 columns, 12 columns means 100% of parent's width. is, if element has class col-lg-6 col-sm-3
, means in large (lg
) screens, element have width: 50%
(6 columns out of 12 total, that's 1/2), , in small (sm
) screens, have width: 25%
(3 columns out of 12 total, that's 1/4).
in case, li
elements should have class col-lg-4 col-md-6
, means take 1/3 of parent's width in large screens , 1/2 in medium-width devices. (large means screens wider 1200px, , media means screens between 992px , 1199px. sizes documented here.)
check jsfiddle. notice because didn't specify col-sm-x
class, in small screens default every li
takes 100% of width. can force specifying class each screen size, if want. (all easier understand once read bootstrap documentation.)
using bootstrap can avoid lot of media queries , focus in keeping css shorter , clearer.
Comments
Post a Comment