Solved

Div grid loses shape when zooming out in firefox

Posted on 2009-03-30
2
479 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
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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
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).

773 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