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 6915963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:32:30+00:00 2026-05-27T09:32:30+00:00

So here is the issue, I have 6 divs that are using jQuery UI

  • 0

So here is the issue, I have 6 divs that are using jQuery UI sortable. They are arranged as can be seen in the image below.

6 green blocks

The image is the layout I am looking for, equal spacing between each of the divs, but with the end ones up against the edges of the container.

My understanding is that this cannot be done by, for example, setting a margin-right:10px on all of them, and removing the margin on the 3rd and 6th elements as these may be dragged to a different position, therefore they would no longer be in the 3rd and 6th position.

I don’t think it can be done either by adding each section into a column div and setting connectWith in the jQuery sortables setting as this set of 6 are themselves inside a div that is connected to other lists, and I dont think you can have connectWith: ‘.connectedSortable, .column’ anyway.

I did also try using the pseudo-class :nth-child(n) but could not get the margins updating correctly when the elements were dragged around 🙁

You can view a jsfiddle here > http://jsfiddle.net/hC5Qy/1/

The width of the boxes are currently set at 32%, the idea being I could set a 2% right/left margin on two of the boxes to give 100% (32 + 32 + 32 + 2 + 2 = 100).

So any ideas?

Are there any JavaScript ways of doing this? Any new CSS3 or HTML5 layouts usable to center the middle box? (I’m not worried about old browser compatibility).

Any help is greatly appreciated!

Thanks

[edit: some code from the fiddle]

HTML:

<div id="area1" class="connectedSortable">       
    <div class="block"><span style="font-size:3em; color:#CCC;">1</span></div>
    <div class="block"><span style="font-size:3em; color:#CCC;">2</span></div>
    <div class="block"><span style="font-size:3em; color:#CCC;">3</span></div>
    <div class="block"><span style="font-size:3em; color:#CCC;">4</span></div>
    <div class="block"><span style="font-size:3em; color:#CCC;">5</span></div>
    <div class="block"><span style="font-size:3em; color:#CCC;">6</span></div>       
</div>

JS:

$(function() {
    $(".connectedSortable ").sortable({
        connectWith: ".connectedSortable"
    });

    $(".connectedSortable").disableSelection();
});

CSS:

#area1, #area2 {
 border:1px solid red;
 float:left;
 width:680px;
 margin-bottom:15px;
 background:#ccc;
}

.block {
    background:green;
    width:32%;
    height:200px;
    float:left;
    margin-right:1%;
    margin-top:10px;
}
  • 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-05-27T09:32:31+00:00Added an answer on May 27, 2026 at 9:32 am

    (deleted prior post):

    It’s not nth-child, it’s the combination of floats and percentages. Here’s a hacky way I “fixed” it:

    http://jsfiddle.net/hC5Qy/5/

    #area1, #area2 {
     border:1px solid red;
     float:left;
     width:680px;
     margin-bottom:15px;
     background:#ccc;
    }
    
    .block:nth-child(3n+3) { 
        margin-right: 0 ; // get rid of extra margin 
        float: right; // floating it right ensures no gap on right if rounding changes gutters
    }
    
    .block {
        background:green;
        width:32%; // 3 of these = 96%
        float: left;
        height:200px;
        margin-right:2%; // 2 of these = 4% for a total of 100%
        margin-top:10px;
    }
    

    Used nth-child to give every 3rd element no right margin and floated right, and narrowed the container. This gives a vague approximation of what you need to do.

    However, with your margins etc. based on % you will have a hard time making it perfectly consistent all the time. At some point there are going to be numbers rounded off to the nearest pixel (browsers render ultimately on pixels!) so your margins can be a pixel or two off.

    There’s more work that can be done to make it more consistent, but I didn’t think you needed me to tweak endlessly at it; I got the impression you just want to know “what’s up?” so that you can continue on it yourself. 😉

    For my two cents, I would use no floats, instead relying on display: inline-block. Inline-block is not supported in IE7 and below, though there are hacks to fake it. If IE6 and 7 are not important to the project, I would refactor the layout using inline-block.

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

Sidebar

Related Questions

I have this jquery issue that seems to only break when using background image
Having an issue here that I have tried everything I can think of but
Here's the issue: I have a hook in IE that reacts on WebBrowser.OnNavigateComplete2 event
Here's the issue: I have 2 data contexts that I would like to do
Here's the issue: I have a list of App names that I want to
I have a rather annoying issue here I can't get my CheckBox CheckedChange event
Here is the issue I am having: I have a large query that needs
This looks like IE8 issue. I have two divs that are side by side
I have a curious issue that's proving difficult. I have five divs stacked vertically
I have a several divs that a refreshed using Ajax after the user clicks

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.