Solved

Div grid loses shape when zooming out in firefox

Posted on 2009-03-30
2
480 Views
Last Modified: 2012-05-06
Hey

My grid is losing its form when I zoom in and out in firefox. Its basically a div container of 1000x1000px with 100 divs inside.

When I zoom out to a certain point it ends up 9 boxes wide and 12 down the last row only having 1 box on it.
I've set padding and margin to 0 and have no idea how to prevent this. No working sample online right now but this code below is ready to test needs no external files.

this is an interesting one for me so thanks for any help

<?php
	/* Loop 10 times to create a 100 square grid within a fixed area */
	//AD = 100 x 100
	
	$gridwidth = 10;
	$gridheight = 10;
	
	$adwidth = 100;
	$adheight = 100;
	
	$divwidth = $gridwidth * $adwidth + 20;
	$divheight = $gridheight * $adheight + 20;
	
	$adnumber = $gridwidth * $gridheight; //gets number of blocks required
?>
 
<!-- HTML IS BUILT FROM HERE ON -->
<div style="width:<?php echo $divwidth;?>px; height:<?php echo $divheight;?>px; border:solid 0px #000000; padding:0; margin:0;">
	<!-- GRID STARTS HERE -->
	<?php
		//       initial value   		
		for ( $counter = 1; $counter <= $adnumber; $counter += 1) 
		{	?>
			<!-- 1 BLOCK STARTS HERE -->
			<div style="width:<?php echo $adwidth;?>px; height:<?php echo $adheight;?>px; float:left; border:solid 1px #000000; padding:0; margin:0;">
				TEST
			</div>
			<!-- 1 BLACK ENDS HERE -->
			<?php  
		}
 
	?>
	<!-- GRID ENDS HERE -->
</div>

Open in new window

0
Comment
Question by:Ryan Bayne
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 5

Accepted Solution

by:
Pantalaim0n earned 125 total points
ID: 24027980
My first question would be: why won't you use a table for this? You can't go wrong with that..

But, if you do want to use this kind of construction:
The problem is that the width of the main DIV gets a few pixels too short when zooming out, so the 10th grid box wraps to the next line.

Working with borders like this gave different results cross-browser (and probably also caused the problem in the first place), so I tried a different approach, making it as cross-browser compatible as possible. Instead of using borders, I overlap 2 DIVs, using a margin of 1, that simulates a border of 1px wide.

The upside is that the cells always make a perfect fit in the grid, the downside is that when zooming out, some "borders" become invisible. See the code below.

But again- why not use tables?

<?php
        /* Loop 10 times to create a 100 square grid within a fixed area */
        //AD = 100 x 100
        
        $gridwidth = 10;
        $gridheight = 10;
        
        $adwidth = 100;
        $adheight = 100;
        
        $divwidth = $gridwidth * $adwidth+20;
        $divheight = $gridheight * $adheight+20;
        
        $adnumber = $gridwidth * $gridheight; //gets number of blocks required
?>
 
<!-- HTML IS BUILT FROM HERE ON -->
<div style="width:<?php echo $divwidth; ?>; height:<?php echo $divheight; ?>; border:solid 0px #000000; padding:0; margin:0; background-color:red;">
        <!-- GRID STARTS HERE -->
        <?php
                //       initial value                  
                for ( $y = 1; $y <= $gridheight; $y += 1) {
					for ( $x = 1; $x <= $gridheight; $x += 1) {
		?>
                        <div style="width:<?php echo $adwidth+2;?>px; height:<?php echo $adheight+2;?>px; float:left; padding:0; margin:0; background-color:#000;"><div style="width:<?php echo $adwidth;?>;height:<?php echo $adheight;?>; padding:0; margin:1px; background-color:#fff;">TEST</div></div>
        <?php  
					}
				}
        ?>
        <!-- GRID ENDS HERE -->
</div>

Open in new window

0
 
LVL 2

Author Comment

by:Ryan Bayne
ID: 24029399
Thats great and taught me a couple of things cheers
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How can I use Javascript to insure proper entry of URL? 6 28
arrays and buttons with user input 2 34
Jquery if else not working ... WHY? 5 26
modify change color of text 9 39
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question