Solved

Div grid loses shape when zooming out in firefox

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
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).

707 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