Current location: Hot Scripts Forums » General Web Coding » HTML/XHTML/XML » div positions


div positions

Reply
  #1 (permalink)  
Old 09-10-10, 09:46 AM
jonnekke jonnekke is offline
Code Guru
 
Join Date: Oct 2005
Location: holland!
Posts: 706
Thanks: 0
Thanked 0 Times in 0 Posts
div positions

Hi there,

I got a few div's nested in another div (container).

This container div is 700x500 px.

The other div's are variable in height, but 150px width.
They are placed above each other like a stack.

I want if the height of 500px is reached the next div will
be placed on the right of the stack and start a new stack,
and so on..

I don't see how this can be done with float...
some a solution on this?

_j
Reply With Quote
  #2 (permalink)  
Old 09-13-10, 03:39 PM
jsNewbie jsNewbie is offline
New Member
 
Join Date: Sep 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Can you post the code or tell us what language(s) you are using? Thanks!
Reply With Quote
  #3 (permalink)  
Old 09-14-10, 05:03 AM
jonnekke jonnekke is offline
Code Guru
 
Join Date: Oct 2005
Location: holland!
Posts: 706
Thanks: 0
Thanked 0 Times in 0 Posts
sure..

this is my code. It's html and php to get data from Mysql.
Each div inside the while loop must be placed the way is
talked about above.

Code:
<?php
$items = mysql_query("SELECT * FROM items") or die(mysql_error());  
?>

<div id="rightcolumn"> 
	<div id="example" style="width:900px; height:450px; float:left; padding:0px 15px 0px 15px; z-index:99; background:#e6e6e6;">             
		<div style="width:170px; height:450px; float:left;">       
			<div id="title" class="koptekst ttfgen">actueel.</div>
			<div id="text" class="fadewel" style="clear:both;">
				<?php
				while($item_info = mysql_fetch_array( $items )) { 
					$title = $item_info['title'];
					$status = $item_info['status'];
				?>
					<div>
						<a href="#" onclick="javascript: $('#nav li:eq(10) a').trigger('click'); slideWelOfNiet('-=700px'); return false;" name="2" class="act"><span style="color:#e3017b; letter-spacing:1px; font-weight:bold;">
							<?=$status?>: </span><?=$title?>
						</a>
					</div>   
				<?php } ?>                                
			</div>                       
		</div>
		<div id="actueel-extra" name="closed" style="width:685px; background:#e6e6e6; padding:0px 15px 0px 15px; height:450px; float:left;">&nbsp;</div> 
	</div>                 
</div>
Reply With Quote
  #4 (permalink)  
Old 09-15-10, 06:35 PM
Yeroon's Avatar
Yeroon Yeroon is offline
Code Master
 
Join Date: Aug 2007
Location: Netherlands, Nijmegen
Posts: 850
Thanks: 2
Thanked 20 Times in 20 Posts
Hi Jonneke,

Since your div's are variable in height you can't really do this without javascript.

I post a sample code below. You can expand the number of divs with variable content to test it out. The div's I mean are the ones with test in it. Just set the ID of those divs to start with: shift

so shift10 if you add another one or shiftBlabla, whatever you like just let it start with: shift

The columns that they go into need to be named divCol1, divCol2 etc. So the number has to go up by 1 for every column.

If this is what you need and it is ok to use javascript, I can make a sample that is more like your own layout and with the php in it.

javascript Code:
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head runat="server">
  4.     <title></title>
  5.  
  6.     <script type="text/javascript">
  7.  
  8.  
  9.         function shiftDivs() {
  10.             var divs = document.getElementsByTagName('div');
  11.             var curHeight = 0; var al = '';
  12.             var curDivCol = 1;
  13.             var shiftDivCounter = 0; //just a counter to fill the array of found elements and their position they should go
  14.             var divsAndPosition = new Array(new Array()); //2 dimensional array holding divs and their position like [element1, 1],[element2, 1],[element3, 2]
  15.             // [the element, the div they go into]
  16.             for (var i = 0; i < divs.length; i++) { //loop through all element
  17.                 if (divs[i].id.indexOf('shift', 0) != -1) { //if the id starts with shift, its one we want to check and if needed move
  18.                     curHeight = curHeight + divs[i].offsetHeight; //calculate the total height so far
  19.                     //offsetHeight is what you want as your divs have no set pixel height .style.height wont work
  20.  
  21.                     if (curHeight > 500) //this div should already shift to right;
  22.                     {
  23.                         curDivCol++; // so we up the column (div) number it should go to
  24.  
  25.                         curHeight = 0; //reset for new measuring
  26.                     }
  27.  
  28.                     //fill the array with the current div we are working with, and the column we want it to go to
  29.  
  30.                     divsAndPosition[shiftDivCounter] = [divs[i], curDivCol];
  31.  
  32.                     //up the array index we are filling
  33.                     shiftDivCounter++;
  34.                     //
  35.                 }
  36.             }
  37.  
  38.             //for each element in our array set the new parent element (column)
  39.             for (var x = 0; x < divsAndPosition.length; x++) {
  40.                 setParent(divsAndPosition[x][0], divsAndPosition[x][1]);
  41.             }
  42.         }
  43.  
  44.         function setParent(el, newParent) {
  45.             //important the container columns should have an ID starting with: divCol
  46.             //and need to have the numbers behind it in order like divCol1, divCol2, divCol3 etc
  47.             //see the divCol divs below.
  48.             var targetDiv = document.getElementById('divCol' + newParent);
  49.  
  50.             targetDiv.appendChild(el);
  51.         }
  52.  
  53.         //all the way at the bottom is where we call this function. Don;t call it here as the browser
  54.         //hasnt rendered the contect yet and doesnt know how high the divs are.
  55.    
  56.     </script>
  57.  
  58. </head>
  59. <body>
  60.     <div>
  61.         <div id="example" style="width: 900px; height: 500px; padding: 0px 15px 0px 15px;
  62.             z-index: 99; background: #e6e6e6;">
  63.             <div style="width: 170px; height: 500px; background-color: #FF0000; float: left;"
  64.                 id="divCol1">
  65.                 <div style='border: 1px solid black; width: 170px;' id='shift1'>
  66.                     1test<br />
  67.                     test<br />
  68.                     test<br />
  69.                     test<br />
  70.                 </div>
  71.                 <div style='border: 1px solid black; width: 170px;' id='shift2'>
  72.                     2test<br />
  73.                     test<br />
  74.                     test<br />
  75.                     test<br />
  76.                     test<br />
  77.                     test<br />
  78.                     test<br />
  79.                 </div>
  80.                 <div style='border: 1px solid black; width: 170px;' id='shift3'>
  81.                     3test<br />
  82.                     test<br />
  83.                     test<br />
  84.                     test<br />
  85.                 </div>
  86.                 <div style='border: 1px solid black; width: 170px;' id='shift4'>
  87.                     4test<br />
  88.                     test<br />
  89.                     test<br />
  90.                 </div>
  91.                 <div style='border: 1px solid black; width: 170px;' id='shift5'>
  92.                     5test<br />
  93.                     test<br />
  94.                     test<br />
  95.                     test<br />
  96.                     test<br />
  97.                 </div>
  98.                 <div style='border: 1px solid black; width: 170px;' id='shift6'>
  99.                     6test<br />
  100.                     test<br />
  101.                 </div>
  102.                 <div style='border: 1px solid black; width: 170px;' id='shift7'>
  103.                     7test<br />
  104.                     test<br />
  105.                     test<br />
  106.                 </div>
  107.                 <div style='border: 1px solid black; width: 170px;' id='shift8'>
  108.                     8test<br />
  109.                     test<br />
  110.                     test<br />
  111.                     test<br />
  112.                 </div>
  113.                 <div style='border: 1px solid black; width: 170px;' id='shift9'>
  114.                     9test<br />
  115.                     test<br />
  116.                     test<br />
  117.                 </div>
  118.             </div>
  119.             <div style="width: 170px; height: 450px; background-color: #00FF00; float: left;"
  120.                 id="divCol2">
  121.             </div>
  122.             <div style="width: 170px; height: 450px; background-color: #FF00FF; float: left;"
  123.                 id="divCol3">
  124.             </div>
  125.             <div style="width: 170px; height: 450px; background-color: #0000FF; float: left;"
  126.                 id="divCol4">
  127.             </div>
  128.         </div>
  129.  
  130.         <script type="text/javascript">
  131.             shiftDivs();
  132.         </script>
  133.  
  134.     </div>
  135. </body>
  136. </html>
__________________
Feel free to thank people if they help you by clicking thanks at a post.
=================================
Make it idiot proof and someone will make a better idiot.
=================================
Realise the impotence of proof reading everything you publish
Reply With Quote
  #5 (permalink)  
Old 09-16-10, 02:19 AM
jonnekke jonnekke is offline
Code Guru
 
Join Date: Oct 2005
Location: holland!
Posts: 706
Thanks: 0
Thanked 0 Times in 0 Posts
This is exactly what I need!! Thnx.

I'll work it out to an exact fit for my site..

thnx again
Reply With Quote
  #6 (permalink)  
Old 09-16-10, 04:33 AM
jonnekke jonnekke is offline
Code Guru
 
Join Date: Oct 2005
Location: holland!
Posts: 706
Thanks: 0
Thanked 0 Times in 0 Posts
got it working... so this was the fix for me

**happy**
Reply With Quote
  #7 (permalink)  
Old 09-19-10, 05:25 PM
Yeroon's Avatar
Yeroon Yeroon is offline
Code Master
 
Join Date: Aug 2007
Location: Netherlands, Nijmegen
Posts: 850
Thanks: 2
Thanked 20 Times in 20 Posts
Well I'm happy too if it makes you happy

Groetjes

Yeroon
__________________
Feel free to thank people if they help you by clicking thanks at a post.
=================================
Make it idiot proof and someone will make a better idiot.
=================================
Realise the impotence of proof reading everything you publish
Reply With Quote
  #8 (permalink)  
Old 08-19-11, 07:08 AM
surinderbhatia surinderbhatia is offline
Newbie Coder
 
Join Date: Aug 2011
Location: India
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
i am also facing this problem when i using the div tag, thanks Jonneke for sharing this great reply
__________________
Free seo tools
Seo Experts
Reply With Quote
  #9 (permalink)  
Old 09-24-11, 07:55 AM
Edge330's Avatar
Edge330 Edge330 is offline
Newbie Coder
 
Join Date: Aug 2011
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
I also had this problem,thanks!
Reply With Quote
  #10 (permalink)  
Old 10-24-11, 03:07 PM
halfdollarhosting's Avatar
halfdollarhosting halfdollarhosting is offline
New Member
 
Join Date: Oct 2011
Location: Seams like at work :)
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Thumbs up Setting it up on halfdollarhosting.com home page failed

I also have same problems m8, i try to set it up on Reliable web hosting packages cheap domains home page and nothing, will try your way now
Thanks a many!

Last edited by halfdollarhosting; 10-24-11 at 03:23 PM.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Space Above Form xavier039 CSS 1 07-13-09 10:52 PM
div css theighost CSS 11 09-14-08 02:30 AM
[SOLVED] delay on html element properties? UnrealEd JavaScript 5 05-05-08 03:23 AM
[SOLVED] Change content in a DIV with links in another DIV s1yfa JavaScript 3 05-04-08 04:10 AM
Can't Understand java script maverickminds JavaScript 1 07-16-06 01:23 PM


All times are GMT -5. The time now is 09:13 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.