Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9057915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T14:35:14+00:00 2026-06-16T14:35:14+00:00

I’m writing a web page that needs to display content in boxes, like this:

  • 0

I’m writing a web page that needs to display content in boxes, like this:

[ 1 ] [ 3 ] [ 5 ]
[ 2 ] [ 4 ] [ 6 ]

Because of varying screen sizes, sometimes the number of rows will vary. For example, a screen that allows for more row to be shown would be arranged like this:

[ 1 ] [ 4 ]
[ 2 ] [ 5 ]
[ 3 ] [ 6 ]

The problem I’m running in to is that when I just float the DIVs to the left, they show up like this:

[ 1 ] [ 2 ] [ 3 ]
[ 4 ] [ 5 ] [ 6 ]

My plan to fix this is to wrap each column in a div, and float that to the left. But because there can be a varying number of rows depending on screen size, I need to accomplish this with jQuery.

I’ve already counted the number of rows with jQuery, I just can’t figure out how to wrap a certain number of divs in a wrapper. Here’s my script so far:

var pageHeight = $("body").innerHeight() - 157; // 157 being the height of the page title
var rowCount = Math.floor(pageHeight / 295); // 295 being the height of each item
var itemCount = $("#itemWrapper").children(".item").length;each item
$("#itemWrapper").height(pageHeight);

So, if rowCount = 3, then I need to wrap the each set of three .items in <div class="column"></div>. And of course remember that there may be only two, or one .item left over.

This seems pretty simple, but I’m having trouble even finding where to begin. As I research this some more, if I figure anything out, I’ll be sure to update my question.

UPDATE 1: Looks like I may be able to use the .wrap() function of jQuery. I just need to figure out how to use it on more than one DIV.

UPDATE 2: I found this bit of code, that looks promising, but I can’t figure out how to make it change based on the number of rows:

for (var i = 0;i < itemCount;i+=3) {
    $(".item").filter(':eq('+i+'),:eq('+(i+1)+'),:eq('+(i+2)+')').wrapAll('<div class="column" />');
};

It seems like for each additional div, it needs to add anther :eq('+(i+1)+') with one number higher. Not sure how to write script that does that, but I’m still researching. If I just change the 3' torowCount` it doesn’t properly close all the added divs.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T14:35:16+00:00Added an answer on June 16, 2026 at 2:35 pm

    You can use CSS3 column properties for browsers that support them.

    Here’s a column wrapping script that will work cross browser. I used a css rule for column class based on column count to set width in percentage

    var colCount = 3,/* hard coded for demo, use your calcs for dynamic*/
        $items = $('.item'),
        items_per_col = Math.ceil($items.length / colCount),
        start = 0;
    
    for (i = 0; i < colCount; i++) {
        var endSlice = start + items_per_col;
        $items.slice(start, endSlice).wrapAll('<div class="col' + colCount + '">');
        start += items_per_col;
    }
    

    DEMO: http://jsfiddle.net/MkGyu/1

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I know there's a lot of other questions out there that deal with this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.