471,887 Members | 1,499 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,887 software developers and data experts.

How to display divs so they don't move when browser is resized?

I am currently working on a site for a client which can be found on my dev site


The problem I am having is I have placed the Images using absolute div's which seems to be the wrong thing to do because while it looks nice in its current resolution when I expand the browser size (or shrink it) the images move all over the place

I have tried relative, absolute, fixed, and float divs nothing seems to just stay where it should! What am I doing wrong?

Here's the code:
Expand|Select|Wrap|Line Numbers
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  6. <title>Untitled Document</title>
  7. <link rel="stylesheet" type="text/css" href="css/style.css"/>
  8. </head>
  10. <body>
  12.     <div id="main">
  13.         <div id="header">
  14.             <div id="search">
  15.                 <form action="" method="get">
  16.                     <input type="text" class="searchbox" name="find" id="find" size="1" />
  17.                     <input type="submit" class="button" name="submit" value="Search" id="submit" />
  18.                 </form>
  19.             </div><!--/search-->
  21.             <div id="menu">
  22.                 <ul class="menu">
  23.                     <li class="parent"><a href="#"><span>Products</span></a>
  24.                         <ul>
  25.                             <li><a href="#"><span>Product 1</span></a></li>
  26.                             <li><a href="#"><span>Product 2</span></a></li>-
  27.                             <li><a href="#"><span>Product 3</span></a></li>
  28.                             <li><a href="#"><span>Product 4</span></a></li>
  29.                         </ul>
  30.                     </li>
  31.                     <li><a href="#"><span>Industries</span></a></li>
  32.                     <li><a href="#"><span>Services</span></a></li>
  33.                     <li><a href="#"><span>Store</span></a></li>
  34.                     <li><a href="#"><span>News</span></a></li>
  35.                     <li><a href="#"><span>About Us</span></a></li>
  36.                 </ul>
  37.             </div><!--/menu-->
  39.             <div class="images">
  40.                 <ul>
  41.                     <li><a href="#"><img src="images/img-01.gif" alt="" /></a></li>
  42.                     <li><a href="#"><img src="images/img-02.gif" alt="" /></a></li>
  43.                     <li><a href="#"><img src="images/img-03.gif" alt="" /></a></li>
  44.                     <li><a href="#"><img src="images/img-04.gif" alt="" /></a></li>
  45.                 </ul>
  46.             </div><!--/images-->
  48.             <div class="submenu">
  49.                 <ul class="menu">
  50.                     <li><a href="#"><span>Contact Us</span></a></li>
  51.                     <li><a href="#"><span>Feedback</span></a></li>
  52.                     <li><a href="#"><span>Sign In</span></a></li>       
  53.                 </ul>
  54.             </div><!--/submenu-->
  55.         </div><!--/header-->
  57.         <div style="position: absolute; left: 390px; top: 230px;">
  58.         <img src="http://www.petervaldivia.com/technology/electricity/powerpoint/image/color_code_table.jpg">
  59.         </div>
  60.         <div style="position: absolute; left: 890px; top: 230px;">
  61.         <a href="http://www.i-gard.com/"><img src="http://www.kudit.com/applications/resistorvalue/images/icon_hr.png"></a>
  62.         </div>
  63. <table width="100%" cellpadding="0" cellspacing="10" border="0">
  64.     <tr>
  65.     <br><br><br>
  66.         <td width="20%" valign="top">
  67.             <p><b><u><font color="blue">What is the function of a Neutral Grounding Resistor?</font></u></b></p>
  68. <br>
  69. <p>Neutral Grounding resistors are similar to fuses in that they do nothing until something in the system goes wrong. Then, like fuses, they protect personnel and equipment from damage.</p>
  70. <br>
  71. <p>Damage comes from two factors, how long the fault lasts and how large the fault is .Ground fault relays trip breakers and limit how long a fault lasts. Neutral grounding resistors limit how large the fault is. </p>
  72. <br>
  73. <p>An effective NGR will both limit the fault current and yet allow sufficient fault current to positively actuate the over-current device.</p>
  75. </p>
  76.         </td>
  77.         <td width="33%" valign="top">
  78.             <p><img src=""></p>
  79.         </td>
  80.         <td width="33%" valign="top">
  81.             <p><img src=""></p>
  82.             <p><img src=""></p>
  83.         </td>
  84.     </tr>
  85. </table>
  86. <br><br><br><br>
  87.         <div id="footer">
  89.         </div>
  90.     </div><!--/main-->
  92. </body>
  93. </html>
The external CSS was done by a more advanced designer/coder that I no longer have access too but his images seem to stay. I was under the impression that these divs would solve my problem but apparently not.

Any insights?
Many thanks,
Nov 12 '10 #1
8 27295
Death Slaught
1,137 1GB
I'm not sure that I'm seeing what you're talking about. What browser are you testing in? They don't move at all for me in Safari, Firefox, Chrome, or Opera.

Thanks, Death
Nov 13 '10 #2
I'm using chrome - the images move mostly when width is changed below standard resolution the shift the right and when I test it on my wide screen or I expand it across my dual screen resolution the images appear on the left hand side of the test instead of where they are supposed to go.

Nov 13 '10 #3
Death Slaught
1,137 1GB
Odd, I still don't see what you're seeing. I'll try to view your page on a PC when I have time. Hopefully someone else will be able to help you soon.

Regards, Death
Nov 13 '10 #4

Here is how the issue appears on extended resolutions (mouseover to view image)
Nov 15 '10 #5
Death Slaught
1,137 1GB
Ah, thanks for the screen shot Adam.

Currently you have the containing division set to be 390px from left of the browser window. In the extended resolution there is more page for the division to go across, but it's still only being moved 390px. Try changing the 390px to 39%. Let me know how it goes.

Thanks, Death
Nov 15 '10 #6
I will try it when im in the office tomorrow.

Another question hough if a Div doesn't exist how do I place it? Let's say I create a new containing div and want it to appear as a right hand column? How can I set parameters is it always just a percentile base?
Nov 15 '10 #7
Death Slaught
1,137 1GB
That entirely depends on the content. Now that I look at this more using absolute positioning isn't even necessary. Also, you're using a table for layout - something you should never do.

Let's see if we can get the current problem solved before adding and removing things.

Thanks, Death
Nov 16 '10 #8
1,206 Expert 1GB
When you absolutely position an element you are removing it from the flow and positioning it relative to the first parent element that is not static. The default is the <html> element. This is what is causing your image to always be X pixels from the top and X pixels from the left of your browser window.

There are several ways to fix this.

1)Use a container div and set it's position to relative around your absolutely positioned divs. This will require you to tweak the top and left values of your absolutely positioned divs.

2)Use a three column layout consisting of three fixed width divs floated to the left followed by a clear.

3)Use a "liquid" or "elastic" layout. This technique uses relative positioning, floats, and percentage based widths to shrink and grow with the browser window. Google can provide you with some examples if you choose this route.

A few things to note. The <u> tag and <font> tag are both deprecated. Tables shouldn't be used for layout. Line breaks shouldn't be used to add padding/margin.

Edit:Just noticed your CSS actually uses technique 1) that I mentioned on your header div. The header is set to relative and the children divs are set to absolute. You can refer to your own CSS for an example. :)
Nov 16 '10 #9

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Gregor | last post: by
1 post views Thread by Tamir Kamara | last post: by
reply views Thread by zermasroor | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.