473,473 Members | 2,236 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Displaying List Items in a Circle

Frinavale
9,735 Recognized Expert Moderator Expert
What I'd like to do is take a list and display it's items in a circle.
For example (the order of the in the circle doesn't matter..except for Item1, it has to be at the top):
Expand|Select|Wrap|Line Numbers
  1.  
  2.         Item1
  3.    Item2      Item3
  4.         Item4
  5.  
I am hoping to avoid JavaScript for this solution but I don't know if it's possible without JavaScript. Obviously Googling "List Items Circle CSS" is not helping (it just keeps pulling up how to display the bullet point as a circle)....

I remember reading a post about positioning something in the middle of the page (here). The post used CSS and some variables (H and W) to position the element in the middle of the page.

I don't know what this technique is called so I'm hoping someone could give me some new keywords to search with...I hope that I can use this technique to position each list item.

Any suggestions as to how to solve this problem would be greatly appreciated.

Thanks

-Frinny
Dec 16 '09 #1
16 10587
drhowarddrfine
7,435 Recognized Expert Expert
Threw this together:
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  2. <html>
  3. <head>
  4. <title></title>
  5. <style type="text/css">
  6. #one,#four{text-align:center}
  7. #two{float:left}
  8. #three{text-align:right}
  9. </style>
  10. <body>
  11. <ul>
  12.         <li id="one">one</li>
  13.         <li id="two">two</li>
  14.         <li id="three">three</li>
  15.         <li id="four">four</li>
  16. </ul>
  17. </body>
  18. </html>
  19.  
I don't like floating things like that but it works. I'd prefer relative or absolute positioning, perhaps placing the ul inside a div.
Dec 16 '09 #2
drhowarddrfine
7,435 Recognized Expert Expert
I remember reading a post about positioning something in the middle of the page (here). The post used CSS and some variables (H and W) to position the element in the middle of the page.
Didn't read this thoroughly. There is no such thing as a CSS variable.
Dec 16 '09 #3
Frinavale
9,735 Recognized Expert Moderator Expert
I guess I should have been a bit more clear.
The list items contain hyperlinks which are the menu for the site.
The menu is a multi-level menu and I wanted to display the first level in the outter circle, the second level as an inner circle of the outter one, and the thrid level as a circle within the second level.

I'm using a CMS that generates the menu in a list for me.
There are no IDs given to the list items except for the "current" list item (given an ID of "current") It's pretty annoying.


-Frinny
Dec 16 '09 #4
Frinavale
9,735 Recognized Expert Moderator Expert
I was thinking about using the position:relative or the position:absolute style instead of floating the elements...

The more I think about how to do this the more I realize that I'm going to have to use JavaScript....

The "circle" algorithm is a little too complicated for CSS (even if it had variables to use).

Thanks for your help Doc

-Frinny
Dec 16 '09 #5
drhowarddrfine
7,435 Recognized Expert Expert
Ah, jeez .
Dec 16 '09 #6
Frinavale
9,735 Recognized Expert Moderator Expert
I figured I'd post the solution using JavaScript for anyone else looking to do this.

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
  2. "http://www.w3.org/TR/html4/strict.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5.  <title>Displaying list items in a circle demo</title>
  6.   <style type="text/css">
  7.   li{
  8.    position:absolute;
  9.    list-style:none;
  10.    width:20%;
  11.    text-align:center;
  12.   }
  13.  </style>
  14. </head>
  15. <body>
  16. <ul>
  17.   <li>3</li>
  18.   <li>4</li>
  19.   <li>5</li>
  20.   <li>6</li>
  21.   <li>7</li>
  22.   <li>8</li>
  23.   <li>9</li>
  24.   <li>10</li>
  25.   <li>11</li>
  26.   <li>12</li>
  27.   <li>1</li>
  28.   <li>2</li>
  29.  </ul>
  30.  <script type="text/javascript">
  31.   var listElements = document.getElementsByTagName("li");
  32.   var step = (2*Math.PI)/listElements.length;
  33.   var angle=0; 
  34.   var circleCenterX = 100;
  35.   var circleCenterY = 100;
  36.   var radius = 90;
  37.   for(var i = 0; i<listElements.length; i++)
  38.   { 
  39.     var element = listElements[i];
  40.     var left=Math.round(circleCenterX+radius*Math.cos(angle));
  41.     var top=Math.round(circleCenterY+radius*Math.sin(angle));
  42.     element.style.left = left+"px";
  43.     element.style.top = top+"px";
  44.     angle+=step;   
  45.   }
  46.  
  47.  </script>
  48. </body>
  49. </html>
Cheers

-Frinny
Dec 16 '09 #7
drhowarddrfine
7,435 Recognized Expert Expert
With a valid doctype, correct?
Dec 16 '09 #8
Frinavale
9,735 Recognized Expert Moderator Expert
Hah :)
Yeah sure...funny thing is that I just whipped this up in the "TryIt Editor" on the w3schools site and they don't include a doctype.

Edited the post to add the doctype :)
Dec 16 '09 #9
Frinavale
9,735 Recognized Expert Moderator Expert
The only thing I'm a little worried about is that the menu is going to look aweful if the user has JavaScript disabled...

Gurr...limitations!
Dec 16 '09 #10
Dormilich
8,658 Recognized Expert Moderator Expert
can’t you use absolute positioning and calculate all the necessary stuff server side?
Dec 16 '09 #11
Frinavale
9,735 Recognized Expert Moderator Expert
Haha. Dorm, do you remember how long it took me to figure out how to retrieve a parameter from an XML file using the framework for that CMS? I couldn't imagine the mess that is involved with generating the menu!

-Frinny
Dec 16 '09 #12
drhowarddrfine
7,435 Recognized Expert Expert
Wrong doctype. New pages should never use the transitional doctype. Use this one:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

Or if one insists on using the XHTML one:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
Dec 16 '09 #13
Dormilich
8,658 Recognized Expert Moderator Expert
I thought it would be that neat ASP I have no idea about, that you were to use as the back end…
Dec 16 '09 #14
Marcin Karol
1 New Member
Does any one know why this script does not working in Google Chrome and Opera?
Feb 24 '11 #15
drhowarddrfine
7,435 Recognized Expert Expert
@Marcin - This thread is over a year old. You should start a new thread about javascript on the javascript board.
Feb 24 '11 #16
Frinavale
9,735 Recognized Expert Moderator Expert
Well I checked it out in Chrome and apparently top refers to the Window DOM object...which didn't make any sense to me since I declared a variable with that name in my code.

After changing the variable names from top and left to liTop and liLeft it worked properly:

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
  2. "http://www.w3.org/TR/html4/strict.dtd">
  3. <head>
  4.  <title>Displaying list items in a circle demo</title>
  5.   <style type="text/css">
  6.   li{
  7.    position:absolute;
  8.    list-style:none;
  9.    width:20%;
  10.    text-align:center;
  11.   }
  12.  </style>
  13. </head>
  14. <body>
  15. <ul>
  16.   <li>3</li>
  17.   <li>4</li>
  18.   <li>5</li>
  19.   <li>6</li>
  20.   <li>7</li>
  21.   <li>8</li>
  22.   <li>9</li>
  23.   <li>10</li>
  24.   <li>11</li>
  25.   <li>12</li>
  26.   <li>1</li>
  27.   <li>2</li>
  28.  </ul>
  29.  <script type="text/javascript">
  30.   var listElements = document.getElementsByTagName("li");
  31.   var step = (2*Math.PI)/listElements.length;
  32.   var angle=0; 
  33.   var circleCenterX = 100;
  34.   var circleCenterY = 100;
  35.   var radius = 90;
  36.   for(var i = 0; i<listElements.length; i++)
  37.   { 
  38.     var element = listElements[i];
  39.     var liLeft=Number(Math.round(circleCenterX+radius*Math.cos(angle)));
  40.     var liTop=Number(Math.round(circleCenterY+radius*Math.sin(angle)));
  41.     element.style.left = liLeft+"px";
  42.     element.style.top = liTop+"px";
  43.     angle+=step;   
  44.   }
  45.  
  46.  </script>
  47. </body>
  48. </html>
Feb 24 '11 #17

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Matthew Wilson | last post by:
I have a list of very simple circle objects: class Circle: def __init__(self, x,y,r): self.center =(x,y) self.r = r I want to write a function that accepts a list of circle objects and then...
3
by: Macca | last post by:
Hi, I am writing a C# application that needs a lot of calibration data. In a previous C++ application, i used a text file which displayed the various calibration data, between 25 and 40...
2
by: Srimadhi | last post by:
Displaying selected items at the top of the listbox Hi, I am having two listboxes - one with ids and second with the related names. When user selects an item in one listbox, the corresponding...
2
by: tshad | last post by:
I am trying to add a different color to some of the rows in my dropdown list and this is how it is suggested to do this in a couple of articles. I have a DropDownList call PayDates and I was...
3
by: hali | last post by:
Hi all I'm working on jsf & I have a problem displaying a list of Items via hand set my code is: <wap:dataTable value="#{predefinedESP.esps}" var="esp" > <wap:column > ...
0
by: hali | last post by:
Hi all I'm working on jsf & I have a problem displaying a list of Items via hand set my code is: <wap:dataTable value="#{predefinedESP.esps}" var="esp" > <wap:column > <waputputText...
10
by: gnewsgroup | last post by:
I've googled and tried various approaches, but could not resolve this problem. The article at MSDN: Displaying Images in a GridView Column only presents a simple case where all data (including the...
5
by: Roy Smith | last post by:
Be kind to me, I'm a CSS newbie... I've been playing with drupal, building a web site (hyc-test.org). I started with the "sky" theme, but didn't like the way it rendered list items in menus. ...
10
by: Aurora88 | last post by:
Hi guys. I have had this problem for so long now it's making me feel so depressed. :x I am trying to display 42 ovals (connect 4) on JPanel but it seems to display a huge white box at the top of...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.