?
Solved

Div grid loses shape when zooming out in firefox

Posted on 2009-03-30
2
Medium Priority
?
482 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 500 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

Tutorial: Introduction to Managing a Linux Server

In this tutorial on systemd, we will explore:
-OS/Distro Adoption
-chkconfig and Other Legacy Commands
-Summary and Key Commands

Question has a verified solution.

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

Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Suggested Courses

762 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