Forum Moderators: not2easy

Message Too Old, No Replies

Positioning divs in a grid with fixed distance between divs

         

stupidcooper

10:34 am on Sep 18, 2009 (gmt 0)

10+ Year Member



Hi, I have set up a home page with 7 divs on. One div is towards the top left and the other 6 are arranged in the middle of the page in a grid formation but with fixed distances between each. This works fine on one resolution but would like to know how I can the margins or padding so that it appears correct on all screens. Below is the code so far,

#apDiv1 {position:absolute;left:74px;top:150px;width:308px;height:217px;z-index:2;}
#apDiv3 {position:absolute;left:474px;top:367px;width:146px;height:106px;z-index:3;}
#apDiv5 {position:absolute;left:682px;top:367px;width:146px;height:106px;z-index:3;}
#apDiv7 {position:absolute;left:882px;top:367px;width:146px;height:106px;z-index:3;}
#apDiv9 {position:absolute;left:474px;top:567px;width:146px;height:106px;z-index:3;}
#apDiv11 {position:absolute;left:682px;top:567px;width:146px;height:106px;z-index:3;}
#apDiv13 {position:absolute;left:882px;top:567px;width:146px;height:106px;z-index:3;}
-->
</style>
</head>
<body background="wallpaperfullsmCOVEv2.jpg">
<div id="apDiv1"><a href="TESTHOME.html" target="_self"><img src="logoframe.jpg" width="308" height="217" /></a></div>
<div id="apDiv3"><a href="A.html" target="_self"><img src="small1A.jpg" width="146" height="106" /></a></div>
<div id="apDiv5"><a href="CLIENTS.html" target="_self"><img src="small1B.jpg" width="146" height="106" /></a></div>
<div id="apDiv7"><a href="C.html" target="_self"><img src="small1C.jpg" width="146" height="106" /></a></div>
<div id="apDiv9"><a href="D.html" target="_self"><img src="small1D.jpg" width="146" height="106" /></a></div>
<div id="apDiv11"><a href="E.html" target="_self"><img src="small1E.jpg" width="146" height="106" /></a></div>
<div id="apDiv13"><a href="F.html" target="_self"><img src="small1F.jpg" width="146" height="106" /></a></div>

Not sure if the above makes it clear about how it needs to look but basically div3 to div 13 are arranged in a grid 3 on the top row and 3 on the bottom row but arranged in the middle of the page but with fixed gaps between them.

whoisgregg

9:47 pm on Sep 22, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you want the div's to resize based on the width of the window, you can use percentage values to position them and determine their width. Here's something to get you started, but you'll probably want to do a lot of tweaking to get it just right. :)

#apDiv3 { position:absolute; left:50%; top:367px; width:12%; height:106px; z-index:3; } 
#apDiv5 { position:absolute; left:64%; top:367px; width:12%; height:106px; z-index:3; }
#apDiv7 { position:absolute; left:77%; top:367px; width:12%; height:106px; z-index:3; }

swa66

9:22 am on Sep 23, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The trick to find a path to a solution is in here:
so that it appears correct on all screens

define "correct".

Once you know what you want to happen it's usually all simple enough.

e.g. if you don't want anything to change but keep your "cluster" of divs in a centered spot: just add a wrapper and center that one, giving it position and letting the child elements use absolute positioning to position themselves inside their parent.

BTW: <div><a><img /></a></div> : that's a superfluous div, you can style the <a> itself just as well.

And I'd make the named used as ID a bit more meaningfull.