tags:

views:

180

answers:

4

I am currently working on a website that is an advertisement portal for businesses. Advertisers can create an account, select various options for listing (State, caregory, etc) and upload a graphic is measured in a multiples of an "unit". An "unit" is an image or a flash file that is 180px wide and 120 high. An advertiser can choose multiple units that are horizontal or vertical, i.e, 2 single units aligned horizontally or 2 single units aligned vertically.

I have gone to the point where the the website is working fine. I am stuck at a point I am going to lay out the "units" and display them properly, without any empty space between them. As an example, if we had 4 advertisements, a horizontal 2 unit ad, a vertical 2 unit and 2 single unit ad, like so -

                  |
                  |
   2 unit ad      |   2 
------------------|  unit 
        |         |   ad
1 unit  | 1 unit  | 
        |         |
        |         |

I am currently storing the advertisements units in a database with attributes that are used in the web form to build a table (i.e., colspan, rowspan, etc). I am not sure if this is the right approach, I fear it is not. I shall be very grateful if I got some advice.

Thanks, Indy

A: 

Have you had a look for any TreeMap controls? Most of them will be commercial offerings, but there may be an open source offering out there.

Zhaph - Ben Duguid
+1  A: 

So the problem is that you have empty space between the units? Does you table include cellspacing="0" and cellpadding="0"?

i.e.

<table cellspacing="0" cellpadding="0">

Not sure how you are storing the units with the attributes. Separating the data and the interface description can mean you have more flexibility and ability to cope with UI change requests. If the attributes are the same for each type of unit then there is probably a lot of duplicated data being stored.

Leah
A: 

That's a tough one. If you want to use divs and css you can try floating the ads. The only problem is that you can't render the divs in an arbitrary order since they won't always try to take up the available room. The same would be true if you were using tables though.

<html>
<head>
    <style>
     div.adcontainer {
      margin: 0px; width: 540px;
     }
     div.ad {
      float: right; margin: 0; padding: 0; width: 180px;
      height: 120px; background: #DDD;
     }
     div.adhorz {
      width: 360px; height: 120px;
     }
     div.advert {
      width: 180px; height: 240px;
     }
    </style>
</head>
<body>
    <div class="adcontainer">
     <div class="ad advert">ad v</div>
     <div class="ad adhorz">ad h</div>
     <div class="ad">ad 1</div>
     <div class="ad">ad 2</div>
    </div>
</body>
</html>
DavGarcia
+2  A: 

IMHO tables are perfect for this job, because the ads have the same rowspan-is and colspan-ish behavior. If you have a method for generating the correct table, stick with it.

Also when I create a HTML table for layout and I do not want spaces between the cells I include cellspacing="0" and cellpadding="0" attributes, like Leah mentioned.

<table cellspacing="0" cellpadding="0" border="0">

Extra table trick:
To obtain a single pixel border between HTML table cells, use the

table 
{ 
    border-collapse: collapse; 
}

CSS property.

Germstorm