Solved

Div grid loses shape when zooming out in firefox

Posted on 2009-03-30
2
478 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
Comment Utility
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
Comment Utility
Thats great and taught me a couple of things cheers
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

728 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now