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

  • Home
  • SEARCH
  • 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 328747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:31:26+00:00 2026-05-12T09:31:26+00:00

I have a page which has DIVs which contain short phrases (one-two words) of

  • 0

I have a page which has DIVs which contain short phrases (one-two words) of varying font sizes, which need to be positioned left-to-right according to a numerical parameter, and vertically so as not to overlap.

It’s like a tag cloud, but there’s information contained in the y-axis as well (“coolness” in this case – http://cool-wall.appspot.com)

How should I lay these out? I’m currently using a very messy series of DIVs like this:

<div style="position:absolute; top:150px;left:10px;right:10px;bottom:10px"> 

<!-- then, repeated, with different top, left and font-size values -->

  <div style="align:center; margin:0; border:none; padding:0; float:left; visibility:visible; position:absolute; top:21%; left:56%; font-size:11px"> 
    <div style="margin-top:0%; margin-right:50%; margin-bottom:0%; margin-left:-50%;"> 
      <a href="foo"><span style="display:inline"> &larr; </span></a> 
      <a href="bar"><span style="display:inline"> Buzz </span></a> 
      <span style="display:inline"> &rarr; </span> 
    </div> 
  </div>

  <!-- of course, followed by a close div -->

</div>

I use a stylesheet to extract some of those styles, and I realise that it’s pretty poor CSS (and HTML)… but this was all I could hack together to do (almost) what I wanted to do. The main problem with the above (apart from it being confusing) is that I can’t set the positioning so it doesn’t overlap, because I don’t know what size the font will be, nor how it will display onscreen.

Happy to use JavaScript to get it right. But I don’t know where to start. Any tips?

  • 1 1 Answer
  • 1 View
  • 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-12T09:31:27+00:00Added an answer on May 12, 2026 at 9:31 am

    The x-value is set on each one, you want to be as high on the page as possible (lowest y) as it can go without overlapping. Not too bad:

    1) Render the container – position:relative; Render each item inside the container with “position:absolute; top:0; left:-1000; ” – draw them all off screen.

    2) One by one, move the element to it’s needed x-coorinate and y=0; Check it with all previous render items to see if it collides, if it does, move it down one pixel until it doesn’t collide:

    var regions = [];
    for(var i = 0; i < items.length; i++){
      var item = items[i];
    
      item.style.x = getX(item); // however you get this...
      var region = YAHOO.util.Dom.getRegion(item);
      var startingTop = region.top;
      for(var iReg = 0; iReg < regions.length; iReg++){
        var existingRegion = regions[iRegion];
        while(region.intersect(existingRegion)){
          region.top++;
          region.bottom++;
        }
        item.style.y = (region.top - startingTop) + 'px';
      }
    }
    

    It’s important to just update the region and not actually move the dom node 1px at a time for performance reasons.

    Put most important items first and they will render with more priority than items below them.

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

Sidebar

Related Questions

I have two divs in my page: leftpart and rightpart which has the following
I have a simple div example with two images one of which has absolute
I have a single page app which has scrolling DIVs as part of the
I have a middleContent div which has two sub-divs acting as columns. The middleMain
I have a web page which has many divs (listed like table rows), and
I have this page which has three peson searchs on them. Basically it's a
I have a page which has an Html.DropDownList which takes in a viewdata parameter.
I have a page which has an Iframe. In that Iframe, there are six
I have a page which has several <canvas> elements. I am passing the canvas
I have a page which has a tree directory of people who work at

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.