jquery - Responsive div columns where column items get shifted on screen resize -


i have 3 columns called <div class="pagecolumnonethird">.

inside each column fetch images , posts using php newest item gets placed in top left column , next 1 in top middle column , third 1 in top right column before goes left column again.

now trying make responsive, when 2 columns displayed, placement of each image/post changed.

example: when there 2 columns side-by-side need first row of items element 1 , 2. second row has element 3 , 4.

is there way using css?

if not, there fast jquery code can me?

code

<!-- first column --> <div class="pagecolumnonethird">     <div class="itemwrap">element 1</div>     <div class="itemwrap">element 4</div>     <div class="itemwrap">element 7</div> </div> <!-- second column --> <div class="pagecolumnonethird">     <div class="itemwrap">element 2</div>     <div class="itemwrap">element 5</div>     <div class="itemwrap">element 8</div> </div> <!-- third column --> <div class="pagecolumnonethird">     <div class="itemwrap">element 3</div>     <div class="itemwrap">element 6</div>     <div class="itemwrap">element 9</div> </div> 

heres jsfiddle well.

you can use 1 wrapper, , use @media queries

.pagecolumnonethird {    font-size: 0;  }  .itemwrap {    background-color: #aeaeae;    margin: 2px 0;    width: 33.3%;    padding: 0 1px;    height: auto;    -moz-box-sizing: border-box;    box-sizing: border-box;    display: inline-block;    font-size: 16px  }  @media (max-width: 768px) {    .itemwrap {      width: 50%    }  }  @media (max-width: 480px) {    .itemwrap {      width: 100%    }  }
<div class="pagecolumnonethird">    <div class="itemwrap">element 1</div>    <div class="itemwrap">element 2</div>    <div class="itemwrap">element 3</div>    <div class="itemwrap">element 4</div>    <div class="itemwrap">element 5</div>    <div class="itemwrap">element 6</div>    <div class="itemwrap">element 7</div>    <div class="itemwrap">element 8</div>    <div class="itemwrap">element 9</div>  </div>

edit based on op comment:

this not looking need allowed different heights on each item element, maintain equal margin without adding empty space in elements. thats why need use 3 separate columns. found picture of need https://prod-foundation-forum.s3.amazonaws.com/uploads/part/part_image/93067/illustration.jpg

for type of layout best thing masonry


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -